From 3eedd34897490c60552bdc9763f058c8052e4e38 Mon Sep 17 00:00:00 2001 From: Charlie Chen Date: Tue, 22 Oct 2024 13:21:16 -0500 Subject: [PATCH 1/3] fix SetGatewayAddress --- zetaclient/chains/solana/signer/signer.go | 3 +- .../chains/solana/signer/signer_test.go | 42 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/zetaclient/chains/solana/signer/signer.go b/zetaclient/chains/solana/signer/signer.go index 3b64a1ff7c..0d762d9006 100644 --- a/zetaclient/chains/solana/signer/signer.go +++ b/zetaclient/chains/solana/signer/signer.go @@ -192,7 +192,8 @@ func (signer *Signer) SetGatewayAddress(address string) { // parse gateway ID and PDA gatewayID, pda, err := contracts.ParseGatewayIDAndPda(address) if err != nil { - signer.Logger().Std.Error().Err(err).Msgf("cannot parse gateway address %s", address) + signer.Logger().Std.Error().Err(err).Msgf("cannot parse gateway address: %s", address) + return } // update gateway ID and PDA diff --git a/zetaclient/chains/solana/signer/signer_test.go b/zetaclient/chains/solana/signer/signer_test.go index c27fb06f7c..b05fc75638 100644 --- a/zetaclient/chains/solana/signer/signer_test.go +++ b/zetaclient/chains/solana/signer/signer_test.go @@ -102,6 +102,48 @@ func Test_NewSigner(t *testing.T) { } } +func Test_SetGatewayAddress(t *testing.T) { + // test parameters + chain := chains.SolanaDevnet + chainParams := sample.ChainParams(chain.ChainId) + chainParams.GatewayAddress = testutils.GatewayAddresses[chain.ChainId] + + // helper functor to create signer + signerCreator := func() *signer.Signer { + s, err := signer.NewSigner(chain, *chainParams, nil, nil, nil, nil, base.DefaultLogger()) + require.NoError(t, err) + return s + } + + // test cases + tests := []struct { + name string + signer *signer.Signer + newAddress string + expected string + }{ + { + name: "should set new gateway address", + signer: signerCreator(), + newAddress: "9Z5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d", + expected: "9Z5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d", + }, + { + name: "should not set invalid gateway address", + signer: signerCreator(), + newAddress: "invalid", + expected: chainParams.GatewayAddress, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + tt.signer.SetGatewayAddress(tt.newAddress) + require.Equal(t, tt.expected, tt.signer.GetGatewayAddress()) + }) + } +} + func Test_SetRelayerBalanceMetrics(t *testing.T) { // test parameters chain := chains.SolanaDevnet From b70120016d22f9e63d37161f4b0b27488b23a865 Mon Sep 17 00:00:00 2001 From: Charlie Chen Date: Tue, 22 Oct 2024 13:26:17 -0500 Subject: [PATCH 2/3] add changelog entry --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index b666c26f7d..babe5d10d8 100644 --- a/changelog.md +++ b/changelog.md @@ -56,6 +56,7 @@ * [2925](https://github.com/zeta-chain/node/pull/2925) - add recover to init chainer to diplay informative message when starting a node from block 1 * [2909](https://github.com/zeta-chain/node/pull/2909) - add legacy messages back to codec for querier backward compatibility * [3018](https://github.com/zeta-chain/node/pull/3018) - support `DepositAndCall` and `WithdrawAndCall` with empty payload +* [3030](https://github.com/zeta-chain/node/pull/3030) - Avoid storing invalid Solana gateway address in the `SetGatewayAddress` ## v20.0.0 From c889ab1011fa924810f9efc70cb917126bb6db27 Mon Sep 17 00:00:00 2001 From: Charlie Chen Date: Tue, 22 Oct 2024 13:52:37 -0500 Subject: [PATCH 3/3] fix gosec --- tests/simulation/sim/sim_state.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/simulation/sim/sim_state.go b/tests/simulation/sim/sim_state.go index 2f314b6c78..c8df9f4f31 100644 --- a/tests/simulation/sim/sim_state.go +++ b/tests/simulation/sim/sim_state.go @@ -248,7 +248,7 @@ func AppStateFromGenesisFileFn( cdc codec.JSONCodec, genesisFile string, ) (tmtypes.GenesisDoc, []simtypes.Account, error) { - bytes, err := os.ReadFile(genesisFile) + bytes, err := os.ReadFile(genesisFile) // #nosec G304 -- genesisFile value is controlled if err != nil { panic(err) }