generated from dymensionxyz/rollapp
-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(cron): add cron module for scheduled execution of wasm contracts #87
Closed
Closed
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
131493d
aib rollapp custom modules
f2c2ee4
Merge pull request #1 from AllInBetsCom/rollapp
rockstarRhino fca95cb
specs for gasless module
hunter1269 87585ac
cron module spec added
85d8643
Merge pull request #2 from AllInBetsCom/gsoec
rockstarRhino f8c97c2
gasless app/ante wiring commented until release of gasless RDK version
bac1ab0
custom gasless module removed
20bdb67
Merge pull request #3 from AllInBetsCom/remove-gasless
rockstarRhino 304d2ce
testcases added for cron module
84a8843
module fixes post review
d2a3cf9
fixed lint issues
f57c84f
post review fixes
6357e42
Merge pull request #4 from AllInBetsCom/cron-fix
rockstarRhino a4910f5
removed unused modules
53d7419
enable param added for cron module
f05ea11
Merge pull request #5 from AllInBetsCom/cron-fix
rockstarRhino 4244071
module refactored post review
aa85548
Merge pull request #6 from AllInBetsCom/cron-fix
rockstarRhino bc79bf7
cron module rework
5a77676
abci logger fix
4b8d0e8
Merge pull request #7 from AllInBetsCom/cron-fix
rockstarRhino 5225980
post review fix
7ce043b
toggle cron job tx added
d32ded0
typos fix
d415177
Merge pull request #8 from AllInBetsCom/cron-fix
rockstarRhino 7be8bd9
store refactor
08b32b9
Merge pull request #9 from AllInBetsCom/cron-fix
rockstarRhino File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package app | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
"time" | ||
|
||
"github.com/CosmWasm/wasmd/x/wasm" | ||
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" | ||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" | ||
"github.com/cosmos/cosmos-sdk/simapp" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sequencerstypes "github.com/dymensionxyz/dymension-rdk/x/sequencers/types" | ||
cronTypes "github.com/dymensionxyz/rollapp-wasm/x/cron/types" | ||
"github.com/stretchr/testify/require" | ||
abci "github.com/tendermint/tendermint/abci/types" | ||
"github.com/tendermint/tendermint/libs/log" | ||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types" | ||
tmtypes "github.com/tendermint/tendermint/types" | ||
dbm "github.com/tendermint/tm-db" | ||
) | ||
|
||
// DefaultConsensusParams defines the default Tendermint consensus params used in | ||
// App testing. | ||
var DefaultConsensusParams = &abci.ConsensusParams{ | ||
Block: &abci.BlockParams{ | ||
MaxBytes: 200000, | ||
MaxGas: -1, | ||
}, | ||
Evidence: &tmproto.EvidenceParams{ | ||
MaxAgeNumBlocks: 302400, | ||
MaxAgeDuration: 504 * time.Hour, // 3 weeks is the max duration | ||
MaxBytes: 10000, | ||
}, | ||
Validator: &tmproto.ValidatorParams{ | ||
PubKeyTypes: []string{ | ||
tmtypes.ABCIPubKeyTypeEd25519, | ||
}, | ||
}, | ||
} | ||
|
||
var ( | ||
ProposerPK = simapp.CreateTestPubKeys(1)[0] | ||
ProposerConsAddr = sdk.ConsAddress(ProposerPK.Address()) | ||
|
||
OperatorPK = secp256k1.GenPrivKey().PubKey() | ||
) | ||
|
||
var TestChainID = "rollappwasm_1234-1" | ||
|
||
func setup(withGenesis bool, invCheckPeriod uint) (*App, map[string]json.RawMessage) { | ||
db := dbm.NewMemDB() | ||
|
||
encCdc := MakeEncodingConfig() | ||
var emptyWasmOpts []wasm.Option | ||
testApp := NewRollapp( | ||
log.NewNopLogger(), db, nil, true, map[int64]bool{}, "/tmp", invCheckPeriod, encCdc, GetEnabledProposals(), EmptyAppOptions{}, emptyWasmOpts, | ||
) | ||
if withGenesis { | ||
return testApp, NewDefaultGenesisState(encCdc.Codec) | ||
} | ||
return testApp, map[string]json.RawMessage{} | ||
} | ||
|
||
// Setup initializes a new Rollapp. A Nop logger is set in Rollapp. | ||
func Setup(t *testing.T, isCheckTx bool) *App { | ||
t.Helper() | ||
|
||
pk, err := cryptocodec.ToTmProtoPublicKey(ProposerPK) | ||
require.NoError(t, err) | ||
|
||
app, genesisState := setup(true, 5) | ||
|
||
// setup for sequencer | ||
seqGenesis := sequencerstypes.GenesisState{ | ||
Params: sequencerstypes.DefaultParams(), | ||
GenesisOperatorAddress: sdk.ValAddress(OperatorPK.Address()).String(), | ||
} | ||
genesisState[sequencerstypes.ModuleName] = app.AppCodec().MustMarshalJSON(&seqGenesis) | ||
|
||
// setup for cron | ||
DefaultSecurityAddress := []string{"cosmos1xkxed7rdzvmyvgdshpe445ddqwn47fru24fnlp"} | ||
params := cronTypes.Params{SecurityAddress: DefaultSecurityAddress} | ||
cronGenesis := cronTypes.GenesisState{ | ||
Params: params, | ||
CronJobs: []cronTypes.CronJob{}, | ||
} | ||
genesisState[cronTypes.ModuleName] = app.AppCodec().MustMarshalJSON(&cronGenesis) | ||
|
||
// for now bank genesis won't be set here, funding accounts should be called with fund utils.FundModuleAccount | ||
|
||
stateBytes, err := json.MarshalIndent(genesisState, "", " ") | ||
require.NoError(t, err) | ||
// init chain will set the validator set and initialize the genesis accounts | ||
app.InitChain( | ||
abci.RequestInitChain{ | ||
Time: time.Time{}, | ||
ChainId: TestChainID, | ||
ConsensusParams: DefaultConsensusParams, | ||
Validators: []abci.ValidatorUpdate{ | ||
{PubKey: pk, Power: 1}, | ||
}, | ||
AppStateBytes: stateBytes, | ||
InitialHeight: 0, | ||
}, | ||
) | ||
|
||
return app | ||
} | ||
|
||
// EmptyAppOptions is a stub implementing AppOptions | ||
type EmptyAppOptions struct{} | ||
|
||
// Get implements AppOptions | ||
func (ao EmptyAppOptions) Get(o string) interface{} { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
syntax = "proto3"; | ||
package wasmrollapp.cron.v1beta1; | ||
|
||
import "gogoproto/gogo.proto"; | ||
|
||
option go_package = "github.com/dymensionxyz/rollapp-wasm/x/cron/types"; | ||
|
||
message CronJob { | ||
// id is the unique identifier for the cron job | ||
uint64 id = 1; | ||
// name is the name of the cron job | ||
string name = 2; | ||
// description is the description of the cron job | ||
string description = 3; | ||
// Msgs that will be executed every period amount of time | ||
repeated MsgContractCron msg_contract_cron = 4 [(gogoproto.nullable) = false]; | ||
// set cron enabled or not | ||
bool enable_cron = 5; | ||
} | ||
|
||
message MsgContractCron { | ||
// Contract is the address of the smart contract | ||
string contract_address = 1; | ||
// Msg is json encoded message to be passed to the contract | ||
string json_msg = 2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
syntax = "proto3"; | ||
package wasmrollapp.cron.v1beta1; | ||
|
||
import "gogoproto/gogo.proto"; | ||
import "wasmrollapp/cron/v1beta1/params.proto"; | ||
import "wasmrollapp/cron/v1beta1/cron.proto"; | ||
|
||
option go_package = "github.com/dymensionxyz/rollapp-wasm/x/cron/types"; | ||
|
||
// GenesisState defines the cron module's genesis state. | ||
message GenesisState { | ||
Params params = 1 [ | ||
(gogoproto.moretags) = "yaml:\"params\"", | ||
(gogoproto.nullable) = false | ||
]; | ||
repeated CronJob cron_jobs = 2 [ | ||
(gogoproto.moretags) = "yaml:\"cron_jobs\"", | ||
(gogoproto.nullable) = false | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
syntax = "proto3"; | ||
package wasmrollapp.cron.v1beta1; | ||
|
||
import "gogoproto/gogo.proto"; | ||
|
||
option go_package = "github.com/dymensionxyz/rollapp-wasm/x/cron/types"; | ||
|
||
// Params defines the set of module parameters. | ||
message Params { | ||
// Security address that can whitelist/delist contract | ||
repeated string security_address = 1 [ | ||
(gogoproto.jsontag) = "security_address,omitempty", | ||
(gogoproto.moretags) = "yaml:\"security_address\"" | ||
]; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we add an
enabled
field here, like suggested?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done