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

Merged
merged 88 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 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
49635de
change test names for tests under TestCoinType_SupportsRefund
kingpinXD Jan 7, 2025
dd8cdcd
rename functions updateState to extractState
kingpinXD Jan 7, 2025
d8284ae
rebase develop
kingpinXD Jan 7, 2025
a760421
rebase develop
kingpinXD Jan 7, 2025
7dd2190
revert format for makefile
kingpinXD Jan 9, 2025
2ecb539
generate files
kingpinXD Jan 10, 2025
556a09e
Merge branch 'develop' into crosschain-simulation-outbound
kingpinXD Jan 10, 2025
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 @@ -14,6 +14,7 @@
* [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
* [3276](https://github.com/zeta-chain/node/pull/3276) - add Solana E2E performance tests and improve Solana outbounds performance
* [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
33 changes: 24 additions & 9 deletions pkg/chains/chain_filters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,57 @@ func TestFilterChains(t *testing.T) {
expected func() []chains.Chain
}{
{
name: "Filter external chains",
name: "filter external chains",
filters: []chains.ChainFilter{chains.FilterExternalChains},
expected: func() []chains.Chain {
return chains.ExternalChainList([]chains.Chain{})
},
},
{
name: "Filter gateway observer chains",
name: "filter gateway observer chains",
filters: []chains.ChainFilter{chains.FilterByGateway(chains.CCTXGateway_observers)},
expected: func() []chains.Chain {
return chains.ChainListByGateway(chains.CCTXGateway_observers, []chains.Chain{})
},
},
{
name: "Filter consensus ethereum chains",
name: "filter consensus ethereum chains",
filters: []chains.ChainFilter{chains.FilterByConsensus(chains.Consensus_ethereum)},
expected: func() []chains.Chain {
return chains.ChainListByConsensus(chains.Consensus_ethereum, []chains.Chain{})
},
},
{
name: "Filter consensus bitcoin chains",
name: "filter consensus bitcoin chains",
filters: []chains.ChainFilter{chains.FilterByConsensus(chains.Consensus_bitcoin)},
expected: func() []chains.Chain {
return chains.ChainListByConsensus(chains.Consensus_bitcoin, []chains.Chain{})
},
},
{
name: "Filter consensus solana chains",
name: "filter consensus solana chains",
filters: []chains.ChainFilter{chains.FilterByConsensus(chains.Consensus_solana_consensus)},
expected: func() []chains.Chain {
return chains.ChainListByConsensus(chains.Consensus_solana_consensus, []chains.Chain{})
},
},
{
name: "Apply multiple filters external chains and gateway observer",
name: "filter evm chains",
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{
chains.FilterExternalChains,
chains.FilterByGateway(chains.CCTXGateway_observers),
Expand All @@ -66,7 +81,7 @@ func TestFilterChains(t *testing.T) {
},
},
{
name: "Apply multiple filters external chains with gateway observer and consensus ethereum",
name: "apply multiple filters external chains with gateway observer and consensus ethereum",
filters: []chains.ChainFilter{
chains.FilterExternalChains,
chains.FilterByGateway(chains.CCTXGateway_observers),
Expand All @@ -85,7 +100,7 @@ func TestFilterChains(t *testing.T) {
},
},
{
name: "Apply multiple filters external chains with gateway observer and consensus bitcoin",
name: "apply multiple filters external chains with gateway observer and consensus bitcoin",
filters: []chains.ChainFilter{
chains.FilterExternalChains,
chains.FilterByGateway(chains.CCTXGateway_observers),
Expand Down Expand Up @@ -116,7 +131,7 @@ func TestFilterChains(t *testing.T) {
},
},
{
name: "Test multiple filters in random order",
name: "test multiple filters in random order",
filters: []chains.ChainFilter{
chains.FilterByGateway(chains.CCTXGateway_observers),
chains.FilterByConsensus(chains.Consensus_ethereum),
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
}
42 changes: 32 additions & 10 deletions pkg/coin/coin_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package coin
package coin_test

import (
"testing"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
"github.com/zeta-chain/node/pkg/coin"
)

func Test_AzetaPerZeta(t *testing.T) {
require.Equal(t, sdk.NewDec(1e18), AzetaPerZeta())
require.Equal(t, sdk.NewDec(1e18), coin.AzetaPerZeta())
}

func Test_GetAzetaDecFromAmountInZeta(t *testing.T) {
Expand Down Expand Up @@ -57,7 +58,7 @@ func Test_GetAzetaDecFromAmountInZeta(t *testing.T) {
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
azeta, err := GetAzetaDecFromAmountInZeta(tc.zetaAmount)
azeta, err := coin.GetAzetaDecFromAmountInZeta(tc.zetaAmount)
tc.err(t, err)
if err == nil {
require.Equal(t, tc.azetaAmount, azeta)
Expand All @@ -71,31 +72,31 @@ func TestGetCoinType(t *testing.T) {
tests := []struct {
name string
coin string
want CoinType
want coin.CoinType
wantErr bool
}{
{
name: "valid coin type 0",
coin: "0",
want: CoinType(0),
want: coin.CoinType(0),
wantErr: false,
},
{
name: "valid coin type 1",
coin: "1",
want: CoinType(1),
want: coin.CoinType(1),
wantErr: false,
},
{
name: "valid coin type 2",
coin: "2",
want: CoinType(2),
want: coin.CoinType(2),
wantErr: false,
},
{
name: "valid coin type 3",
coin: "3",
want: CoinType(3),
want: coin.CoinType(3),
wantErr: false,
},
{
Expand All @@ -106,7 +107,7 @@ func TestGetCoinType(t *testing.T) {
{
name: "invalid coin type large number",
coin: "4",
want: CoinType(4),
want: coin.CoinType(4),
},
{
name: "invalid coin type non-integer",
Expand All @@ -117,7 +118,7 @@ func TestGetCoinType(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := GetCoinType(tt.coin)
got, err := coin.GetCoinType(tt.coin)
if tt.wantErr {
require.Error(t, err)
} else {
Expand All @@ -127,3 +128,24 @@ func TestGetCoinType(t *testing.T) {
})
}
}

func TestCoinType_SupportsRefund(t *testing.T) {
tests := []struct {
name string
c coin.CoinType
want bool
}{
{"should support refund for ERC20", coin.CoinType_ERC20, true},
{"should support refund forGas", coin.CoinType_Gas, true},
{"should support refund forZeta", coin.CoinType_Zeta, true},
{"should not support refund forCmd", coin.CoinType_Cmd, false},
{"should not support refund forUnknown", coin.CoinType(100), false},
}
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)
}
})
}
}
25 changes: 25 additions & 0 deletions pkg/memo/memo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package memo_test

import (
"encoding/hex"
mathrand "math/rand"
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
"github.com/zeta-chain/node/pkg/memo"
"github.com/zeta-chain/node/testutil/sample"
crosschaintypes "github.com/zeta-chain/node/x/crosschain/types"
)

Expand Down Expand Up @@ -306,6 +308,9 @@ func Test_Memo_DecodeFromBytes(t *testing.T) {

func Test_DecodeLegacyMemoHex(t *testing.T) {
expectedShortMsgResult, err := hex.DecodeString("1a2b3c4d5e6f708192a3b4c5d6e7f808")
r := mathrand.New(mathrand.NewSource(42))
address, data, memoHex := sample.MemoFromRand(r)

require.NoError(t, err)
tests := []struct {
name string
Expand All @@ -324,6 +329,8 @@ func Test_DecodeLegacyMemoHex(t *testing.T) {
{"empty msg", "", common.Address{}, nil, false},
{"invalid hex", "invalidHex", common.Address{}, nil, true},
{"short msg", "1a2b3c4d5e6f708192a3b4c5d6e7f808", common.Address{}, expectedShortMsgResult, false},
{"random message", sample.EthAddress().String(), common.Address{}, nil, true},
{"random message with hex encoding", memoHex, address, data, false},
}

for _, tt := range tests {
Expand All @@ -339,3 +346,21 @@ func Test_DecodeLegacyMemoHex(t *testing.T) {
})
}
}

func Test_DecodeLegacyMemoHex_Random(t *testing.T) {
r := mathrand.New(mathrand.NewSource(42))

// Generate a random memo hex
randomMemo := common.BytesToAddress([]byte{0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x12, 0x34, 0x56, 0x78}).
Hex()
randomData := []byte(sample.StringRandom(r, 10))
randomMemoHex := hex.EncodeToString(append(common.FromHex(randomMemo), randomData...))

// Decode the random memo hex
addr, data, err := memo.DecodeLegacyMemoHex(randomMemoHex)

// Validate the results
require.NoError(t, err)
require.Equal(t, common.HexToAddress(randomMemo), addr)
require.Equal(t, randomData, data)
}
Loading
Loading