Skip to content

Commit

Permalink
test: configure Solana gateway program id for E2E tests (#3154)
Browse files Browse the repository at this point in the history
* configure Solana gateway program id in E2E test

* add changelog entry
  • Loading branch information
ws4charlie authored Nov 14, 2024
1 parent d6ed9aa commit 07120f1
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 27 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmd/zetae2e/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
3 changes: 1 addition & 2 deletions cmd/zetae2e/config/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion cmd/zetae2e/config/local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,7 @@ contracts:
custody: "0xff3135df4F2775f4091b81f4c7B6359CfA07862a"
erc20: "0xbD1e64A22B9F92D9Ce81aA9B4b0fFacd80215564"
test_dapp: "0xBFF76e77D56B3C1202107f059425D56f0AEF87Ed"
gateway: "0xF0deebCB0E9C829519C4baa794c5445171973826"
gateway: "0xF0deebCB0E9C829519C4baa794c5445171973826"
solana:
gateway_program_id: "94U5AHQMKkV5txNJ17QPXWoh474PheGou6cNP2FEuL1d"
spl: ""
6 changes: 5 additions & 1 deletion cmd/zetae2e/config/localnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ""
5 changes: 4 additions & 1 deletion cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion e2e/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down
6 changes: 3 additions & 3 deletions e2e/runner/setup_solana.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions e2e/runner/solana.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions pkg/contracts/solana/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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")
)
Expand Down
4 changes: 2 additions & 2 deletions pkg/contracts/solana/inbound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion zetaclient/chains/solana/observer/inbound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions zetaclient/orchestrator/orchestrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions zetaclient/testutils/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 07120f1

Please sign in to comment.