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

fix: SetGatewayAddress might set invalid gateway address #3030

Merged
merged 3 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tests/simulation/sim/sim_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@
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

Check warning on line 251 in tests/simulation/sim/sim_state.go

View check run for this annotation

Codecov / codecov/patch

tests/simulation/sim/sim_state.go#L251

Added line #L251 was not covered by tests
if err != nil {
panic(err)
}
Expand Down
3 changes: 2 additions & 1 deletion zetaclient/chains/solana/signer/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions zetaclient/chains/solana/signer/signer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
ws4charlie marked this conversation as resolved.
Show resolved Hide resolved

// 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())
})
}
ws4charlie marked this conversation as resolved.
Show resolved Hide resolved
}

func Test_SetRelayerBalanceMetrics(t *testing.T) {
// test parameters
chain := chains.SolanaDevnet
Expand Down
Loading