Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito committed Nov 7, 2024
1 parent 6b38084 commit a3f6653
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 71 deletions.
2 changes: 1 addition & 1 deletion cmd/zetae2e/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func RunnerFromConfig(
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.SPL = config.DoubleQuotedString(r.SPLAddr.String())
conf.Contracts.Solana.SPLAddr = config.DoubleQuotedString(r.SPLAddr.String())

conf.Contracts.EVM.ZetaEthAddr = config.DoubleQuotedString(r.ZetaEthAddr.Hex())
conf.Contracts.EVM.ConnectorEthAddr = config.DoubleQuotedString(r.ConnectorEthAddr.Hex())
Expand Down
2 changes: 1 addition & 1 deletion cmd/zetae2e/config/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func setContractsFromConfig(r *runner.E2ERunner, conf config.Config) error {
r.GatewayProgram = solana.MustPublicKeyFromBase58(c)
}

if c := conf.Contracts.Solana.SPL; c != "" {
if c := conf.Contracts.Solana.SPLAddr; c != "" {
r.SPLAddr = solana.MustPublicKeyFromBase58(c.String())
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,8 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
// TODO move under admin tests
// https://github.com/zeta-chain/node/issues/3085
e2etests.TestSolanaWhitelistSPLName,
e2etests.TestSolanaDepositSPLName,
e2etests.TestSolanaDepositSPLAndCallName,
e2etests.TestSPLDepositName,
e2etests.TestSPLDepositAndCallName,
}
eg.Go(solanaTestRoutine(conf, deployerRunner, verbose, solanaTests...))
}
Expand Down
4 changes: 2 additions & 2 deletions e2e/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ type Contracts struct {
Solana Solana `yaml:"solana"`
}

// Solana contains the addresses of predeployed contracts on the Solana chain
// Solana contains the addresses of predeployed contracts and accounts on the Solana chain
type Solana struct {
GatewayProgramID string `yaml:"gateway_program_id"`
SPL DoubleQuotedString `yaml:"spl"`
SPLAddr DoubleQuotedString `yaml:"spl"`
}

// EVM contains the addresses of predeployed contracts on the EVM chain
Expand Down
12 changes: 6 additions & 6 deletions e2e/e2etests/e2etests.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ const (
TestSolanaDepositAndCallRefundName = "solana_deposit_and_call_refund"
TestSolanaDepositRestrictedName = "solana_deposit_restricted"
TestSolanaWithdrawRestrictedName = "solana_withdraw_restricted"
TestSolanaDepositSPLName = "solana_deposit_spl"
TestSolanaDepositSPLAndCallName = "solana_deposit_spl_and_call"
TestSPLDepositName = "spl_deposit"
TestSPLDepositAndCallName = "spl_deposit_and_call"

/**
* TON tests
Expand Down Expand Up @@ -465,20 +465,20 @@ var AllE2ETests = []runner.E2ETest{
TestSolanaWhitelistSPL,
),
runner.NewE2ETest(
TestSolanaDepositSPLName,
TestSPLDepositName,
"deposit SPL into ZEVM",
[]runner.ArgDefinition{
{Description: "amount of spl tokens", DefaultValue: "500000"},
},
TestSolanaDepositSPL,
TestSPLDeposit,
),
runner.NewE2ETest(
TestSolanaDepositSPLAndCallName,
TestSPLDepositAndCallName,
"deposit SPL into ZEVM and call",
[]runner.ArgDefinition{
{Description: "amount of spl tokens", DefaultValue: "500000"},
},
TestSolanaDepositSPLAndCall,
TestSPLDepositAndCall,
),
/*
TON tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
crosschaintypes "github.com/zeta-chain/node/x/crosschain/types"
)

func TestSolanaDepositSPL(r *runner.E2ERunner, args []string) {
func TestSPLDeposit(r *runner.E2ERunner, args []string) {
require.Len(r, args, 1)
amount := parseInt(r, args[0])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
crosschaintypes "github.com/zeta-chain/node/x/crosschain/types"
)

func TestSolanaDepositSPLAndCall(r *runner.E2ERunner, args []string) {
func TestSPLDepositAndCall(r *runner.E2ERunner, args []string) {
require.Len(r, args, 1)
amount := parseInt(r, args[0])

Expand Down Expand Up @@ -53,7 +53,7 @@ func TestSolanaDepositSPLAndCall(r *runner.E2ERunner, args []string) {
utils.RequireCCTXStatus(r, cctx, crosschaintypes.CctxStatus_OutboundMined)

// check if example contract has been called, bar value should be set to amount
utils.MustHaveCalledExampleContract(r, contract, big.NewInt(500_000))
utils.MustHaveCalledExampleContract(r, contract, big.NewInt(int64(amount)))

// verify balances are updated
pdaBalanceAfter, err := r.SolanaClient.GetTokenAccountBalance(r.Ctx, pdaAta, rpc.CommitmentConfirmed)
Expand Down
94 changes: 42 additions & 52 deletions e2e/runner/solana.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,60 +37,53 @@ func (r *E2ERunner) CreateDepositInstruction(
data []byte,
amount uint64,
) solana.Instruction {
// compute the gateway PDA address
pdaComputed := r.ComputePdaAddress()
pda := r.ComputePdaAddress()
programID := r.GatewayProgram

// create 'deposit' instruction
inst := &solana.GenericInstruction{}
accountSlice := []*solana.AccountMeta{}
accountSlice = append(accountSlice, solana.Meta(signer).WRITE().SIGNER())
accountSlice = append(accountSlice, solana.Meta(pdaComputed).WRITE())
accountSlice = append(accountSlice, solana.Meta(solana.SystemProgramID))
inst.ProgID = programID
inst.AccountValues = accountSlice

var err error
inst.DataBytes, err = borsh.Serialize(solanacontract.DepositInstructionParams{
depositData, err := borsh.Serialize(solanacontract.DepositInstructionParams{
Discriminator: solanacontract.DiscriminatorDeposit,
Amount: amount,
Memo: append(receiver.Bytes(), data...),
})
require.NoError(r, err)

return inst
return &solana.GenericInstruction{
ProgID: programID,
DataBytes: depositData,
AccountValues: []*solana.AccountMeta{
solana.Meta(signer).WRITE().SIGNER(),
solana.Meta(pda).WRITE(),
solana.Meta(solana.SystemProgramID),
},
}
}

// CreateWhitelistSPLMintInstruction creates a 'whitelist_spl_mint' instruction
func (r *E2ERunner) CreateWhitelistSPLMintInstruction(
signer solana.PublicKey,
whitelistEntry solana.PublicKey,
whitelistCandidate solana.PublicKey,
signer, whitelistEntry, whitelistCandidate solana.PublicKey,
) solana.Instruction {
// compute the gateway PDA address
pdaComputed := r.ComputePdaAddress()
pda := r.ComputePdaAddress()
programID := r.GatewayProgram

// create 'whitelist_spl_mint' instruction
inst := &solana.GenericInstruction{}
accountSlice := []*solana.AccountMeta{}
accountSlice = append(accountSlice, solana.Meta(whitelistEntry).WRITE())
accountSlice = append(accountSlice, solana.Meta(whitelistCandidate))
accountSlice = append(accountSlice, solana.Meta(pdaComputed).WRITE())
accountSlice = append(accountSlice, solana.Meta(signer).WRITE().SIGNER())
accountSlice = append(accountSlice, solana.Meta(solana.SystemProgramID))
inst.ProgID = programID
inst.AccountValues = accountSlice

var err error
inst.DataBytes, err = borsh.Serialize(solanacontract.WhitelistInstructionParams{
data, err := borsh.Serialize(solanacontract.WhitelistInstructionParams{
Discriminator: solanacontract.DiscriminatorWhitelistSplMint,
// remaining fields are empty because no tss signature is needed if signer is admin account
})
require.NoError(r, err)

return inst
return &solana.GenericInstruction{
ProgID: programID,
DataBytes: data,
AccountValues: []*solana.AccountMeta{
solana.Meta(whitelistEntry).WRITE(),
solana.Meta(whitelistCandidate),
solana.Meta(pda).WRITE(),
solana.Meta(signer).WRITE().SIGNER(),
solana.Meta(solana.SystemProgramID),
},
}
}

// CreateDepositSPLInstruction creates a 'deposit_spl' instruction
func (r *E2ERunner) CreateDepositSPLInstruction(
amount uint64,
signer solana.PublicKey,
Expand All @@ -101,32 +94,29 @@ func (r *E2ERunner) CreateDepositSPLInstruction(
receiver ethcommon.Address,
data []byte,
) solana.Instruction {
// compute the gateway PDA address
pdaComputed := r.ComputePdaAddress()
pda := r.ComputePdaAddress()
programID := r.GatewayProgram

// create 'deposit_spl' instruction
inst := &solana.GenericInstruction{}
accountSlice := []*solana.AccountMeta{}
accountSlice = append(accountSlice, solana.Meta(signer).WRITE().SIGNER())
accountSlice = append(accountSlice, solana.Meta(pdaComputed))
accountSlice = append(accountSlice, solana.Meta(whitelistEntry))
accountSlice = append(accountSlice, solana.Meta(mint))
accountSlice = append(accountSlice, solana.Meta(solana.TokenProgramID))
accountSlice = append(accountSlice, solana.Meta(from).WRITE())
accountSlice = append(accountSlice, solana.Meta(to).WRITE())
inst.ProgID = programID
inst.AccountValues = accountSlice

var err error
inst.DataBytes, err = borsh.Serialize(solanacontract.DepositInstructionParams{
depositSPLData, err := borsh.Serialize(solanacontract.DepositInstructionParams{
Discriminator: solanacontract.DiscriminatorDepositSPL,
Amount: amount,
Memo: append(receiver.Bytes(), data...),
})
require.NoError(r, err)

return inst
return &solana.GenericInstruction{
ProgID: programID,
DataBytes: depositSPLData,
AccountValues: []*solana.AccountMeta{
solana.Meta(signer).WRITE().SIGNER(),
solana.Meta(pda),
solana.Meta(whitelistEntry),
solana.Meta(mint),
solana.Meta(solana.TokenProgramID),
solana.Meta(from).WRITE(),
solana.Meta(to).WRITE(),
},
}
}

// CreateSignedTransaction creates a signed transaction from instructions
Expand Down
14 changes: 10 additions & 4 deletions zetaclient/chains/solana/observer/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,10 @@ func (ob *Observer) ParseInboundAsDeposit(
var inst solanacontracts.DepositInstructionParams
err := borsh.Deserialize(&inst, instruction.Data)
if err != nil {
return nil, nil
ob.Logger().
Inbound.Err(err).
Msgf("failed to deserialize instruction data for sig %s instruction %d", tx.Signatures[0], instructionIndex)
return nil, err

Check warning on line 283 in zetaclient/chains/solana/observer/inbound.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/observer/inbound.go#L280-L283

Added lines #L280 - L283 were not covered by tests
}

// check if the instruction is a deposit or not
Expand All @@ -291,7 +294,7 @@ func (ob *Observer) ParseInboundAsDeposit(
ob.Logger().
Inbound.Err(err).
Msgf("unable to get signer for sig %s instruction %d", tx.Signatures[0], instructionIndex)
return nil, nil
return nil, err

Check warning on line 297 in zetaclient/chains/solana/observer/inbound.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/observer/inbound.go#L297

Added line #L297 was not covered by tests
}

// build inbound event
Expand Down Expand Up @@ -326,7 +329,10 @@ func (ob *Observer) ParseInboundAsDepositSPL(
var inst solanacontracts.DepositSPLInstructionParams
err := borsh.Deserialize(&inst, instruction.Data)
if err != nil {
return nil, nil
ob.Logger().
Inbound.Err(err).
Msgf("failed to deserialize instruction data for sig %s instruction %d", tx.Signatures[0], instructionIndex)
return nil, err
}

Check warning on line 336 in zetaclient/chains/solana/observer/inbound.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/observer/inbound.go#L332-L336

Added lines #L332 - L336 were not covered by tests

// check if the instruction is a deposit spl or not
Expand All @@ -340,7 +346,7 @@ func (ob *Observer) ParseInboundAsDepositSPL(
ob.Logger().
Inbound.Err(err).
Msgf("unable to get signer and spl for sig %s instruction %d", tx.Signatures[0], instructionIndex)
return nil, nil
return nil, err
}

Check warning on line 350 in zetaclient/chains/solana/observer/inbound.go

View check run for this annotation

Codecov / codecov/patch

zetaclient/chains/solana/observer/inbound.go#L346-L350

Added lines #L346 - L350 were not covered by tests

// build inbound event
Expand Down

0 comments on commit a3f6653

Please sign in to comment.