From 07120f14f6403e2f6b651eef576598e61d76f187 Mon Sep 17 00:00:00 2001 From: Charlie Chen <34498985+ws4charlie@users.noreply.github.com> Date: Thu, 14 Nov 2024 10:30:03 -0600 Subject: [PATCH] test: configure Solana gateway program id for E2E tests (#3154) * configure Solana gateway program id in E2E test * add changelog entry --- changelog.md | 1 + cmd/zetae2e/config/config.go | 2 +- cmd/zetae2e/config/contracts.go | 3 +-- cmd/zetae2e/config/local.yml | 5 ++++- cmd/zetae2e/config/localnet.yml | 6 +++++- cmd/zetae2e/local/local.go | 5 ++++- e2e/config/config.go | 2 +- e2e/runner/setup_solana.go | 6 +++--- e2e/runner/solana.go | 6 ++---- pkg/contracts/solana/gateway.go | 9 ++++++--- pkg/contracts/solana/inbound_test.go | 4 ++-- zetaclient/chains/solana/observer/inbound_test.go | 2 +- zetaclient/orchestrator/orchestrator_test.go | 5 ++--- zetaclient/testutils/constant.go | 10 ++++++---- 14 files changed, 39 insertions(+), 27 deletions(-) diff --git a/changelog.md b/changelog.md index 244bc9d08d..07b7d10bc5 100644 --- a/changelog.md +++ b/changelog.md @@ -12,6 +12,7 @@ * [3075](https://github.com/zeta-chain/node/pull/3075) - ton: withdraw concurrent, deposit & revert. * [3105](https://github.com/zeta-chain/node/pull/3105) - split Bitcoin E2E tests into two runners for deposit and withdraw +* [3154](https://github.com/zeta-chain/node/pull/3154) - configure Solana gateway program id for E2E tests ### Refactor * [3118](https://github.com/zeta-chain/node/pull/3118) - zetaclient: remove hsm signer diff --git a/cmd/zetae2e/config/config.go b/cmd/zetae2e/config/config.go index 65e5418f53..cffee5943b 100644 --- a/cmd/zetae2e/config/config.go +++ b/cmd/zetae2e/config/config.go @@ -55,7 +55,7 @@ func RunnerFromConfig( // ExportContractsFromRunner export contracts from the runner to config using a source config func ExportContractsFromRunner(r *runner.E2ERunner, conf config.Config) config.Config { // copy contracts from deployer runner - conf.Contracts.Solana.GatewayProgramID = r.GatewayProgram.String() + conf.Contracts.Solana.GatewayProgramID = config.DoubleQuotedString(r.GatewayProgram.String()) conf.Contracts.Solana.SPLAddr = config.DoubleQuotedString(r.SPLAddr.String()) conf.Contracts.EVM.ZetaEthAddr = config.DoubleQuotedString(r.ZetaEthAddr.Hex()) diff --git a/cmd/zetae2e/config/contracts.go b/cmd/zetae2e/config/contracts.go index 5c46cdc047..6b508096b5 100644 --- a/cmd/zetae2e/config/contracts.go +++ b/cmd/zetae2e/config/contracts.go @@ -31,7 +31,7 @@ func setContractsFromConfig(r *runner.E2ERunner, conf config.Config) error { // set Solana contracts if c := conf.Contracts.Solana.GatewayProgramID; c != "" { - r.GatewayProgram = solana.MustPublicKeyFromBase58(c) + r.GatewayProgram = solana.MustPublicKeyFromBase58(c.String()) } if c := conf.Contracts.Solana.SPLAddr; c != "" { @@ -242,7 +242,6 @@ func setContractsFromConfig(r *runner.E2ERunner, conf config.Config) error { } // v2 contracts - if c := conf.Contracts.EVM.Gateway; c != "" { r.GatewayEVMAddr, err = c.AsEVMAddress() if err != nil { diff --git a/cmd/zetae2e/config/local.yml b/cmd/zetae2e/config/local.yml index 5cc87be394..e4ec147e49 100644 --- a/cmd/zetae2e/config/local.yml +++ b/cmd/zetae2e/config/local.yml @@ -116,4 +116,7 @@ contracts: custody: "0xff3135df4F2775f4091b81f4c7B6359CfA07862a" erc20: "0xbD1e64A22B9F92D9Ce81aA9B4b0fFacd80215564" test_dapp: "0xBFF76e77D56B3C1202107f059425D56f0AEF87Ed" - gateway: "0xF0deebCB0E9C829519C4baa794c5445171973826" \ No newline at end of file + gateway: "0xF0deebCB0E9C829519C4baa794c5445171973826" + solana: + gateway_program_id: "94U5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d" + spl: "" \ No newline at end of file diff --git a/cmd/zetae2e/config/localnet.yml b/cmd/zetae2e/config/localnet.yml index 24e51223ef..15f1e332f6 100644 --- a/cmd/zetae2e/config/localnet.yml +++ b/cmd/zetae2e/config/localnet.yml @@ -98,4 +98,8 @@ rpcs: ton_sidecar_url: "http://ton:8000" zetacore_grpc: "zetacore0:9090" zetacore_rpc: "http://zetacore0:26657" -# contracts will be populated on first run +contracts: +# configure localnet solana gateway program id + solana: + gateway_program_id: "94U5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d" + spl: "" \ No newline at end of file diff --git a/cmd/zetae2e/local/local.go b/cmd/zetae2e/local/local.go index 5507d95014..6dc466cef8 100644 --- a/cmd/zetae2e/local/local.go +++ b/cmd/zetae2e/local/local.go @@ -224,7 +224,10 @@ func localE2ETest(cmd *cobra.Command, _ []string) { deployerRunner.SetupEVMV2() if testSolana { - deployerRunner.SetupSolana(conf.AdditionalAccounts.UserSolana.SolanaPrivateKey.String()) + deployerRunner.SetupSolana( + conf.Contracts.Solana.GatewayProgramID.String(), + conf.AdditionalAccounts.UserSolana.SolanaPrivateKey.String(), + ) } deployerRunner.SetZEVMSystemContracts() diff --git a/e2e/config/config.go b/e2e/config/config.go index 33a8c2bea8..22382c1fa1 100644 --- a/e2e/config/config.go +++ b/e2e/config/config.go @@ -120,7 +120,7 @@ type Contracts struct { // Solana contains the addresses of predeployed contracts and accounts on the Solana chain type Solana struct { - GatewayProgramID string `yaml:"gateway_program_id"` + GatewayProgramID DoubleQuotedString `yaml:"gateway_program_id"` SPLAddr DoubleQuotedString `yaml:"spl"` } diff --git a/e2e/runner/setup_solana.go b/e2e/runner/setup_solana.go index 1a46326d02..28a4fb65fa 100644 --- a/e2e/runner/setup_solana.go +++ b/e2e/runner/setup_solana.go @@ -27,11 +27,11 @@ func (r *E2ERunner) SetupSolanaAccount() { } // SetupSolana sets Solana contracts and params -func (r *E2ERunner) SetupSolana(deployerPrivateKey string) { +func (r *E2ERunner) SetupSolana(gatewayID, deployerPrivateKey string) { r.Logger.Print("⚙️ initializing gateway program on Solana") // set Solana contracts - r.GatewayProgram = solana.MustPublicKeyFromBase58(solanacontracts.SolanaGatewayProgramID) + r.GatewayProgram = solana.MustPublicKeyFromBase58(gatewayID) // get deployer account balance privkey, err := solana.PrivateKeyFromBase58(deployerPrivateKey) @@ -141,7 +141,7 @@ func (r *E2ERunner) ensureSolanaChainParams() error { BallotThreshold: observertypes.DefaultBallotThreshold, MinObserverDelegation: observertypes.DefaultMinObserverDelegation, IsSupported: true, - GatewayAddress: solanacontracts.SolanaGatewayProgramID, + GatewayAddress: r.GatewayProgram.String(), } updateMsg := observertypes.NewMsgUpdateChainParams(creator, chainParams) diff --git a/e2e/runner/solana.go b/e2e/runner/solana.go index d395c60d76..380219dee4 100644 --- a/e2e/runner/solana.go +++ b/e2e/runner/solana.go @@ -21,8 +21,7 @@ import ( // ComputePdaAddress computes the PDA address for the gateway program func (r *E2ERunner) ComputePdaAddress() solana.PublicKey { seed := []byte(solanacontract.PDASeed) - GatewayProgramID := solana.MustPublicKeyFromBase58(solanacontract.SolanaGatewayProgramID) - pdaComputed, bump, err := solana.FindProgramAddress([][]byte{seed}, GatewayProgramID) + pdaComputed, bump, err := solana.FindProgramAddress([][]byte{seed}, r.GatewayProgram) require.NoError(r, err) r.Logger.Info("computed pda: %s, bump %d\n", pdaComputed, bump) @@ -33,8 +32,7 @@ func (r *E2ERunner) ComputePdaAddress() solana.PublicKey { // SolanaRentPayerPDA computes the rent payer PDA (Program Derived Address) address for the gateway program func (r *E2ERunner) SolanaRentPayerPDA() solana.PublicKey { seed := []byte(solanacontract.RentPayerPDASeed) - GatewayProgramID := solana.MustPublicKeyFromBase58(solanacontract.SolanaGatewayProgramID) - pdaComputed, bump, err := solana.FindProgramAddress([][]byte{seed}, GatewayProgramID) + pdaComputed, bump, err := solana.FindProgramAddress([][]byte{seed}, r.GatewayProgram) require.NoError(r, err) r.Logger.Info("computed rent payer pda: %s, bump %d\n", pdaComputed, bump) diff --git a/pkg/contracts/solana/gateway.go b/pkg/contracts/solana/gateway.go index bf674aa081..7465893149 100644 --- a/pkg/contracts/solana/gateway.go +++ b/pkg/contracts/solana/gateway.go @@ -8,9 +8,6 @@ import ( ) const ( - // SolanaGatewayProgramID is the program ID of the Solana gateway program - SolanaGatewayProgramID = "94U5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d" - // PDASeed is the seed for the Solana gateway program derived address PDASeed = "meta" @@ -29,16 +26,22 @@ const ( var ( // DiscriminatorInitialize returns the discriminator for Solana gateway 'initialize' instruction DiscriminatorInitialize = idlgateway.IDLGateway.GetDiscriminator("initialize") + // DiscriminatorInitializeRentPayer returns the discriminator for Solana gateway 'initialize_rent_payer' instruction DiscriminatorInitializeRentPayer = idlgateway.IDLGateway.GetDiscriminator("initialize_rent_payer") + // DiscriminatorDeposit returns the discriminator for Solana gateway 'deposit' instruction DiscriminatorDeposit = idlgateway.IDLGateway.GetDiscriminator("deposit") + // DiscriminatorDepositSPL returns the discriminator for Solana gateway 'deposit_spl_token' instruction DiscriminatorDepositSPL = idlgateway.IDLGateway.GetDiscriminator("deposit_spl_token") + // DiscriminatorWithdraw returns the discriminator for Solana gateway 'withdraw' instruction DiscriminatorWithdraw = idlgateway.IDLGateway.GetDiscriminator("withdraw") + // DiscriminatorWithdrawSPL returns the discriminator for Solana gateway 'withdraw_spl_token' instruction DiscriminatorWithdrawSPL = idlgateway.IDLGateway.GetDiscriminator("withdraw_spl_token") + // DiscriminatorWhitelist returns the discriminator for Solana gateway 'whitelist_spl_mint' instruction DiscriminatorWhitelistSplMint = idlgateway.IDLGateway.GetDiscriminator("whitelist_spl_mint") ) diff --git a/pkg/contracts/solana/inbound_test.go b/pkg/contracts/solana/inbound_test.go index 00bb17f994..7b19badf7a 100644 --- a/pkg/contracts/solana/inbound_test.go +++ b/pkg/contracts/solana/inbound_test.go @@ -47,7 +47,7 @@ func Test_ParseInboundAsDeposit(t *testing.T) { // create observer chainParams := sample.ChainParams(chain.ChainId) - chainParams.GatewayAddress = testutils.GatewayAddresses[chain.ChainId] + chainParams.GatewayAddress = testutils.OldSolanaGatewayAddressDevnet require.NoError(t, err) // expected result @@ -79,7 +79,7 @@ func Test_ParseInboundAsDepositSPL(t *testing.T) { // create observer chainParams := sample.ChainParams(chain.ChainId) - chainParams.GatewayAddress = testutils.GatewayAddresses[chain.ChainId] + chainParams.GatewayAddress = testutils.OldSolanaGatewayAddressDevnet // expected result // solana e2e deployer account diff --git a/zetaclient/chains/solana/observer/inbound_test.go b/zetaclient/chains/solana/observer/inbound_test.go index c38d3ae281..28c31f04db 100644 --- a/zetaclient/chains/solana/observer/inbound_test.go +++ b/zetaclient/chains/solana/observer/inbound_test.go @@ -71,7 +71,7 @@ func Test_FilterInboundEvents(t *testing.T) { // create observer chainParams := sample.ChainParams(chain.ChainId) - chainParams.GatewayAddress = testutils.GatewayAddresses[chain.ChainId] + chainParams.GatewayAddress = testutils.OldSolanaGatewayAddressDevnet ob, err := observer.NewObserver(chain, nil, *chainParams, nil, nil, 60, database, base.DefaultLogger(), nil) require.NoError(t, err) diff --git a/zetaclient/orchestrator/orchestrator_test.go b/zetaclient/orchestrator/orchestrator_test.go index b86e85cc15..4b85ccbb03 100644 --- a/zetaclient/orchestrator/orchestrator_test.go +++ b/zetaclient/orchestrator/orchestrator_test.go @@ -14,7 +14,6 @@ import ( "github.com/zeta-chain/node/pkg/chains" "github.com/zeta-chain/node/pkg/coin" - solanacontracts "github.com/zeta-chain/node/pkg/contracts/solana" "github.com/zeta-chain/node/testutil/sample" crosschainkeeper "github.com/zeta-chain/node/x/crosschain/keeper" crosschaintypes "github.com/zeta-chain/node/x/crosschain/types" @@ -41,7 +40,7 @@ func Test_GetUpdatedSigner(t *testing.T) { tonChainParams = mocks.MockChainParams(tonChain.ChainId, 100) ) - solChainParams.GatewayAddress = solanacontracts.SolanaGatewayProgramID + solChainParams.GatewayAddress = testutils.GatewayAddresses[solChain.ChainId] // new chain params in AppContext evmChainParamsNew := mocks.MockChainParams(evmChainParams.ChainId, 100) @@ -126,7 +125,7 @@ func Test_GetUpdatedChainObserver(t *testing.T) { tonChainParams = mocks.MockChainParams(tonChain.ChainId, 100) ) - solChainParams.GatewayAddress = solanacontracts.SolanaGatewayProgramID + solChainParams.GatewayAddress = testutils.GatewayAddresses[solChain.ChainId] tonChainParams.GatewayAddress = sample.GenerateTONAccountID().ToRaw() // new chain params in AppContext diff --git a/zetaclient/testutils/constant.go b/zetaclient/testutils/constant.go index f776c7019f..304cd859c3 100644 --- a/zetaclient/testutils/constant.go +++ b/zetaclient/testutils/constant.go @@ -39,12 +39,14 @@ const ( EventERC20Withdraw = "Withdrawn" ) +// OldSolanaGatewayAddressDevnet is the old gateway address deployed on Solana devnet +const OldSolanaGatewayAddressDevnet = "94U5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d" + // GatewayAddresses contains constants gateway addresses for testing var GatewayAddresses = map[int64]string{ - // Gateway address on Solana devnet - // NOTE: currently different deployer key pair is used for development compared to live networks - // as live networks key pair is sensitive information at this point, can be unified once we have deployments completed - chains.SolanaDevnet.ChainId: "94U5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d", + // Solana gateway addresses + chains.SolanaDevnet.ChainId: "ZETAjseVjuFsxdRxo6MmTCvqFwb3ZHUx56Co3vCmGis", + chains.SolanaMainnet.ChainId: "ZETAjseVjuFsxdRxo6MmTCvqFwb3ZHUx56Co3vCmGis", } // ConnectorAddresses contains constants ERC20 connector addresses for testing