Skip to content
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

test: add crosschain and observer operations #3207

Open
wants to merge 81 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 69 commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
9369869
add crosschain decoders
kingpinXD Oct 24, 2024
873153d
decoders test
kingpinXD Oct 28, 2024
422d03b
add oeprations
kingpinXD Oct 31, 2024
39d9863
add fungible deploy contracts
kingpinXD Oct 31, 2024
84d2089
add fungible deploy contracts
kingpinXD Nov 1, 2024
5d68917
add simulation for observer module
kingpinXD Nov 5, 2024
c4dfcd7
add comments for crosschain operations
kingpinXD Nov 5, 2024
fa1234f
add comments for observer and fungible operations
kingpinXD Nov 5, 2024
9e3c7b3
rebase develop
kingpinXD Nov 6, 2024
9f976c0
generate files
kingpinXD Nov 7, 2024
bacd4b2
debug import export test
kingpinXD Nov 7, 2024
2b0509a
fix import export tests
kingpinXD Nov 7, 2024
d03ed5f
fix import export tests
kingpinXD Nov 7, 2024
7070211
fix app determinism test
kingpinXD Nov 8, 2024
cda3f22
update codecov.yml
kingpinXD Nov 8, 2024
9172df7
reduce weight for DeployedSystemContracts operation
kingpinXD Nov 8, 2024
8526eab
add new function to generate eth address from provided randomness
kingpinXD Nov 8, 2024
ea92069
Update x/fungible/simulation/decoders.go
kingpinXD Nov 8, 2024
977a22c
Update testutil/sample/sample.go
kingpinXD Nov 8, 2024
863cf0b
add validations
kingpinXD Nov 8, 2024
44abb89
add validations
kingpinXD Nov 8, 2024
94ecd5e
add randmoness to tss
kingpinXD Nov 8, 2024
13f919f
make requested changes 1
kingpinXD Nov 13, 2024
4975947
update state.go file
kingpinXD Nov 13, 2024
eea9fd4
update state.go file
kingpinXD Nov 13, 2024
083d861
change chains.IsEVMChain to chains.IsEthereumChain in deposit tests
kingpinXD Nov 14, 2024
dee623d
add basic structure for outbound vote message
kingpinXD Nov 15, 2024
111b0d3
add randomised outbound message
kingpinXD Nov 19, 2024
5c958d0
add cointype randomisation to inbound message
kingpinXD Nov 19, 2024
a1940b9
add cointype gas
kingpinXD Nov 22, 2024
734fcde
add cointype erc20
kingpinXD Nov 22, 2024
a3fb140
add outbound tracker
kingpinXD Nov 23, 2024
1dc5135
improve outbound tracker nonce selection
kingpinXD Nov 25, 2024
bbb2e0b
remove block limit for outbound tracker
kingpinXD Nov 26, 2024
f6f02c6
add operation remove outbound tracker
kingpinXD Nov 26, 2024
1b1331b
add operation whitelist erc20
kingpinXD Nov 27, 2024
a8adac6
fix unit tests
kingpinXD Nov 27, 2024
de55103
fix unit tests
kingpinXD Nov 27, 2024
e5c5fc7
fix Abort CCTX test
kingpinXD Nov 27, 2024
6bb4c02
add operation refund aborted cctx
kingpinXD Dec 3, 2024
d0b7fc8
add operation update rate limiter flags
kingpinXD Dec 3, 2024
8bf7a94
add operation UpdateErc20PauseStatus
kingpinXD Dec 3, 2024
7b973d0
add additional checks to whitelist erc20
kingpinXD Dec 4, 2024
84979bc
add default gas prices to the state
kingpinXD Dec 4, 2024
0189453
add default gas prices to the state
kingpinXD Dec 4, 2024
df1b22c
update zeta accounting genesis
kingpinXD Dec 4, 2024
48e5392
update operation whitelist erc20 to not try whitelisting duplicate as…
kingpinXD Dec 4, 2024
5d3be6e
add check for aborted status when finalizing an outbound
kingpinXD Dec 5, 2024
7ee9138
add check for aborted status when finalizing an outbound
kingpinXD Dec 5, 2024
658c59e
reduce errors for RefundAbortedCCTX
kingpinXD Dec 6, 2024
d612907
reduce errors for RefundAbortedCCTX
kingpinXD Dec 6, 2024
41aa11b
reafactor update TSS to use existing cctx
kingpinXD Dec 6, 2024
8ecf2dd
remove setting nonce to cctx twice
kingpinXD Dec 7, 2024
863b4cd
set observe count for even is observer set is empty
kingpinXD Dec 9, 2024
ede755b
add updte keygen message
kingpinXD Dec 9, 2024
adf2c12
add update chain params
kingpinXD Dec 9, 2024
010ecb6
add SimulateMsgResetChainNonces
kingpinXD Dec 10, 2024
f6852b2
add more operations from observer module
kingpinXD Dec 10, 2024
038df39
add helper functions
kingpinXD Dec 11, 2024
1d3ff29
format code
kingpinXD Dec 11, 2024
7c14f50
add additional check to voting messages to for existing ballots
kingpinXD Dec 11, 2024
b5181d5
add msg vote tss
kingpinXD Dec 11, 2024
31b233b
add msg vote tss
kingpinXD Dec 11, 2024
2de15bf
rebase develop
kingpinXD Dec 11, 2024
25fef78
remove isPending check for aborted cctx
kingpinXD Dec 11, 2024
5c05afe
fix unit tests
kingpinXD Dec 11, 2024
30f1e65
add comments to simulation_test.go
kingpinXD Dec 11, 2024
f32e676
add comments and unit tests
kingpinXD Dec 12, 2024
a90a6eb
add comments to operations
kingpinXD Dec 12, 2024
1d431cc
refactor based on comments
kingpinXD Dec 12, 2024
42d1389
fix formating
kingpinXD Dec 12, 2024
42bf24d
improve formating for decoders.go
kingpinXD Dec 12, 2024
fd1dec3
remove overflow check when not needed
kingpinXD Dec 12, 2024
2be31f2
resolve comments 2
kingpinXD Dec 13, 2024
c6c8000
add protocol v2
kingpinXD Dec 13, 2024
507b430
generate files 2
kingpinXD Dec 13, 2024
7504de4
reduce weight of message enable CCTX
kingpinXD Dec 13, 2024
9f249f6
add solana address from rand
kingpinXD Dec 16, 2024
456d59a
make changes based on feedback
kingpinXD Dec 17, 2024
8fea9b0
refacctor updateCrossChainState to updateCrosschainState
kingpinXD Dec 18, 2024
fb46049
rename Maxed to MaxReached
kingpinXD Dec 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ test-sim-fullappsimulation:
$(call run-sim-test,"TestFullAppSimulation",TestFullAppSimulation,100,200,30m)

test-sim-import-export:
$(call run-sim-test,"test-import-export",TestAppImportExport,50,100,30m)
$(call run-sim-test,"test-import-export",TestAppImportExport,100,200,30m)

test-sim-after-import:
$(call run-sim-test,"test-sim-after-import",TestAppSimulationAfterImport,100,200,30m)
Expand All @@ -430,6 +430,12 @@ test-sim-after-import-long: runsim
@echo "Running application simulation-after-import. This may take several minute"
@$(BINDIR)/runsim -Jobs=4 -SimAppPkg=$(SIMAPP) -ExitOnFail 500 50 TestAppSimulationAfterImport

# Use to run all simulation tests quickly (for example, before a creating a PR)
test-sim-quick:
$(call run-sim-test,"test-full-app-sim",TestFullAppSimulation,10,20,30m)
$(call run-sim-test,"test-import-export",TestAppImportExport,10,20,30m)
$(call run-sim-test,"test-sim-after-import",TestAppSimulationAfterImport,10,20,30m)

.PHONY: \
test-sim-nondeterminism \
test-sim-fullappsimulation \
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* [3205](https://github.com/zeta-chain/node/issues/3205) - move Bitcoin revert address test to advanced group to avoid upgrade test failure
* [3254](https://github.com/zeta-chain/node/pull/3254) - rename v2 E2E tests as evm tests and rename old evm tests as legacy
* [3095](https://github.com/zeta-chain/node/pull/3095) - initialize simulation tests for custom zetachain modules
* [3207](https://github.com/zeta-chain/node/pull/3207) - add simulation test operations for all messages in crosschain and observer module

## Refactor

Expand Down
5 changes: 5 additions & 0 deletions pkg/chains/chain_filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ func FilterByConsensus(cs Consensus) ChainFilter {
return func(chain Chain) bool { return chain.Consensus == cs }
}

// FilterByVM filters chains by VM type
func FilterByVM(vm Vm) ChainFilter {
return func(chain Chain) bool { return chain.Vm == vm }
}

// FilterChains applies a list of filters to a list of chains
func FilterChains(chainList []Chain, filters ...ChainFilter) []Chain {
// Apply each filter to the list of supported chains
Expand Down
15 changes: 15 additions & 0 deletions pkg/chains/chain_filters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ func TestFilterChains(t *testing.T) {
return chains.ChainListByConsensus(chains.Consensus_solana_consensus, []chains.Chain{})
},
},
{
name: "Filter vm evm chains",
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
filters: []chains.ChainFilter{
chains.FilterByVM(chains.Vm_evm),
},
expected: func() []chains.Chain {
var chainList []chains.Chain
for _, chain := range chains.ExternalChainList([]chains.Chain{}) {
if chain.Vm == chains.Vm_evm {
chainList = append(chainList, chain)
}
}
return chainList
},
},
{
name: "Apply multiple filters external chains and gateway observer",
filters: []chains.ChainFilter{
Expand Down
4 changes: 4 additions & 0 deletions pkg/coin/coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ func GetAzetaDecFromAmountInZeta(zetaAmount string) (sdk.Dec, error) {
zetaToAzetaConvertionFactor := sdk.NewDecFromInt(sdk.NewInt(1000000000000000000))
return zetaDec.Mul(zetaToAzetaConvertionFactor), nil
}

func (c CoinType) SupportsRefund() bool {
return c == CoinType_ERC20 || c == CoinType_Gas || c == CoinType_Zeta
}
28 changes: 28 additions & 0 deletions pkg/coin/coint_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package coin_test

import (
"testing"

"github.com/zeta-chain/node/pkg/coin"
)

func TestCoinType_SupportsRefund(t *testing.T) {
tests := []struct {
name string
c coin.CoinType
want bool
}{
{"ERC20", coin.CoinType_ERC20, true},
{"Gas", coin.CoinType_Gas, true},
{"Zeta", coin.CoinType_Zeta, true},
{"Cmd", coin.CoinType_Cmd, false},
{"Unknown", coin.CoinType(100), false},
Comment on lines +15 to +19
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test name full lowercase

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to keep this as it is , since these are all proper nouns

}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.c.SupportsRefund(); got != tt.want {
t.Errorf("CoinType.SupportsRefund() = %v, want %v", got, tt.want)
}
})
}
}
38 changes: 29 additions & 9 deletions simulation/simulation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ func init() {
zetasimulation.GetSimulatorFlags()
}

// StoreKeysPrefixes defines a struct used in comparing two keys for two different stores
// SkipPrefixes is used to skip certain prefixes when comparing the stores
type StoreKeysPrefixes struct {
A storetypes.StoreKey
B storetypes.StoreKey
Expand All @@ -66,6 +64,12 @@ func interBlockCacheOpt() func(*baseapp.BaseApp) {
}

// TestAppStateDeterminism runs a full application simulation , and produces multiple blocks as per the config
// It does the following
// 1. It runs the simulation multiple times with the same seed value
// 2. It checks the apphash at the end of each run
// 3. It compares the apphash at the end of each run to check for determinism
// 4. Repeat steps 1-3 for multiple seeds

// It checks the determinism of the application by comparing the apphash at the end of each run to other runs
// The following test certifies that , for the same set of operations ( irrespective of what the operations are ) ,
// we would reach the same final state if the initial state is the same
Expand Down Expand Up @@ -179,7 +183,10 @@ func TestAppStateDeterminism(t *testing.T) {
}

// TestFullAppSimulation runs a full simApp simulation with the provided configuration.
// At the end of the run it tries to export the genesis state to make sure the export works.
// This test does the following
// 1. It runs a full simulation with the provided configuration
// 2. It exports the state and validators
// 3. Verifies that the run and export were successful
func TestFullAppSimulation(t *testing.T) {

config := zetasimulation.NewConfigFromFlags()
Expand Down Expand Up @@ -252,6 +259,15 @@ func TestFullAppSimulation(t *testing.T) {
zetasimulation.PrintStats(db)
}

// TestAppImportExport tests the application simulation after importing the state exported from a previous.At a high level,it does the following
// 1. It runs a full simulation and exports the state
// 2. It creates a new app, and db
// 3. It imports the exported state into the new app
// 4. It compares the key value pairs for the two apps.The comparison function takes a list of keys to skip as an input as well
// a. First app which ran the simulation
// b. Second app which imported the state

// This can verify the export and import process do not modify the state in anyway irrespective of the operations performed
func TestAppImportExport(t *testing.T) {
config := zetasimulation.NewConfigFromFlags()

Expand All @@ -270,7 +286,6 @@ func TestAppImportExport(t *testing.T) {
t.Skip("skipping application simulation")
}
require.NoError(t, err, "simulation setup failed")

t.Cleanup(func() {
if err := db.Close(); err != nil {
require.NoError(t, err, "Error closing new database")
Expand Down Expand Up @@ -375,7 +390,6 @@ func TestAppImportExport(t *testing.T) {
ChainID: SimAppChainID,
})

t.Log("initializing genesis for the new app using exported genesis state")
// Use genesis state from the first app to initialize the second app
newSimApp.ModuleManager().InitGenesis(ctxNewSimApp, newSimApp.AppCodec(), genesisState)
newSimApp.StoreConsensusParams(ctxNewSimApp, exported.ConsensusParams)
Expand All @@ -390,7 +404,7 @@ func TestAppImportExport(t *testing.T) {
// We will need to explore this further to find a definitive answer
// TODO:https://github.com/zeta-chain/node/issues/3263

// {simApp.GetKey(authtypes.StoreKey), newSimApp.GetKey(authtypes.StoreKey), [][]byte{}},
//{simApp.GetKey(authtypes.StoreKey), newSimApp.GetKey(authtypes.StoreKey), [][]byte{}},
{
simApp.GetKey(stakingtypes.StoreKey), newSimApp.GetKey(stakingtypes.StoreKey),
[][]byte{
Expand Down Expand Up @@ -439,6 +453,12 @@ func TestAppImportExport(t *testing.T) {
}
}

// TestAppSimulationAfterImport tests the application simulation after importing the state exported from a previous simulation run.
// It does the following steps
// 1. It runs a full simulation and exports the state
// 2. It creates a new app, and db
// 3. It imports the exported state into the new app
// 4. It runs a simulation on the new app and verifies that there is error in the second simulation
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
func TestAppSimulationAfterImport(t *testing.T) {
config := zetasimulation.NewConfigFromFlags()

Expand Down Expand Up @@ -516,16 +536,15 @@ func TestAppSimulationAfterImport(t *testing.T) {
exported, err := simApp.ExportAppStateAndValidators(true, []string{}, []string{})
require.NoError(t, err)

// Setup a new app with new database and directory
newDB, newDir, _, _, err := cosmossimutils.SetupSimulation(
config,
SimDBBackend+"_new",
SimDBName+"_new",
zetasimulation.FlagVerboseValue,
zetasimulation.FlagEnabledValue,
)

require.NoError(t, err, "simulation setup failed")

t.Cleanup(func() {
if err := newDB.Close(); err != nil {
require.NoError(t, err, "Error closing new database")
Expand All @@ -534,7 +553,6 @@ func TestAppSimulationAfterImport(t *testing.T) {
require.NoError(t, err, "Error removing directory")
}
})

newSimApp, err := zetasimulation.NewSimApp(
logger,
newDB,
Expand All @@ -544,12 +562,14 @@ func TestAppSimulationAfterImport(t *testing.T) {
)
require.NoError(t, err)

// Initialize the new app with the exported genesis state of the first run
t.Log("Importing genesis into the new app")
newSimApp.InitChain(abci.RequestInitChain{
ChainId: SimAppChainID,
AppStateBytes: exported.AppState,
})

// Run simulation on the new app
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
stopEarly, simParams, simErr = simulation.SimulateFromSeed(
t,
os.Stdout,
Expand Down
Loading
Loading