-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* sol withdraw and call and e2e test * fmt * fix solana e2e tests * fix msg hash unit tests * cleanup * bump gateway.so * cleanup unused function * cleanup * PR comments * linter * PR comments * PR comments
- Loading branch information
Showing
25 changed files
with
1,232 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[4,156,87,189,200,207,193,67,118,37,217,115,157,40,134,151,249,231,68,2,190,65,17,126,65,183,171,211,67,236,0,114,58,185,194,112,159,227,216,198,215,6,171,71,237,0,253,253,183,17,201,181,129,216,22,233,192,113,248,203,247,19,100,21] |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package e2etests | ||
|
||
import ( | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/gagliardetto/solana-go" | ||
"github.com/near/borsh-go" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/zeta-chain/node/e2e/runner" | ||
"github.com/zeta-chain/node/e2e/utils" | ||
solanacontract "github.com/zeta-chain/node/pkg/contracts/solana" | ||
crosschaintypes "github.com/zeta-chain/node/x/crosschain/types" | ||
) | ||
|
||
// TestSolanaWithdrawAndCall executes withdrawAndCall on zevm and calls connected program on solana | ||
// message and zevm sender are stored in connected program pda, and withdrawn lamports are stored | ||
// in connected program pda and account provided in remaining accounts to demonstrate that lamports | ||
// can be moved to accounts in connected program as well as gateway program | ||
func TestSolanaWithdrawAndCall(r *runner.E2ERunner, args []string) { | ||
require.Len(r, args, 1) | ||
|
||
withdrawAmount := utils.ParseBigInt(r, args[0]) | ||
|
||
// get ERC20 SOL balance before withdraw | ||
balanceBefore, err := r.SOLZRC20.BalanceOf(&bind.CallOpts{}, r.EVMAddress()) | ||
require.NoError(r, err) | ||
r.Logger.Info("runner balance of SOL before withdraw: %d", balanceBefore) | ||
|
||
require.Equal(r, 1, balanceBefore.Cmp(withdrawAmount), "Insufficient balance for withdrawal") | ||
|
||
// parse withdraw amount (in lamports), approve amount is 1 SOL | ||
approvedAmount := new(big.Int).SetUint64(solana.LAMPORTS_PER_SOL) | ||
require.Equal( | ||
r, | ||
-1, | ||
withdrawAmount.Cmp(approvedAmount), | ||
"Withdrawal amount must be less than the approved amount: %v", | ||
approvedAmount, | ||
) | ||
|
||
// load deployer private key | ||
privkey := r.GetSolanaPrivKey() | ||
|
||
// check balances before withdraw | ||
connected := solana.MustPublicKeyFromBase58("4xEw862A2SEwMjofPkUyd4NEekmVJKJsdHkK3UkAtDrc") | ||
connectedPda, err := solanacontract.ComputeConnectedPdaAddress(connected) | ||
require.NoError(r, err) | ||
|
||
connectedPdaInfoBefore, err := r.SolanaClient.GetAccountInfo(r.Ctx, connectedPda) | ||
require.NoError(r, err) | ||
|
||
senderBefore, err := r.SolanaClient.GetAccountInfo(r.Ctx, privkey.PublicKey()) | ||
require.NoError(r, err) | ||
|
||
// withdraw and call | ||
tx := r.WithdrawAndCallSOLZRC20(connected, withdrawAmount, approvedAmount, []byte("hello")) | ||
|
||
// wait for the cctx to be mined | ||
cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, tx.Hash().Hex(), r.CctxClient, r.Logger, r.CctxTimeout) | ||
utils.RequireCCTXStatus(r, cctx, crosschaintypes.CctxStatus_OutboundMined) | ||
|
||
// get ERC20 SOL balance after withdraw | ||
balanceAfter, err := r.SOLZRC20.BalanceOf(&bind.CallOpts{}, r.EVMAddress()) | ||
require.NoError(r, err) | ||
r.Logger.Info("runner balance of SOL after withdraw: %d", balanceAfter) | ||
|
||
// check if the balance is reduced correctly | ||
amountReduced := new(big.Int).Sub(balanceBefore, balanceAfter) | ||
require.True(r, amountReduced.Cmp(withdrawAmount) >= 0, "balance is not reduced correctly") | ||
|
||
// check pda account info of connected program | ||
connectedPdaInfo, err := r.SolanaClient.GetAccountInfo(r.Ctx, connectedPda) | ||
require.NoError(r, err) | ||
|
||
sender, err := r.SolanaClient.GetAccountInfo(r.Ctx, privkey.PublicKey()) | ||
require.NoError(r, err) | ||
|
||
type ConnectedPdaInfo struct { | ||
Discriminator [8]byte | ||
LastSender [20]byte | ||
LastMessage string | ||
} | ||
pda := ConnectedPdaInfo{} | ||
err = borsh.Deserialize(&pda, connectedPdaInfo.Bytes()) | ||
require.NoError(r, err) | ||
|
||
require.Equal(r, "hello", pda.LastMessage) | ||
require.Equal(r, r.ZEVMAuth.From.String(), common.BytesToAddress(pda.LastSender[:]).String()) | ||
|
||
// connected program splits amount between account provided in remaining accounts, and its own pda | ||
require.Equal(r, connectedPdaInfoBefore.Value.Lamports+withdrawAmount.Uint64()/2, connectedPdaInfo.Value.Lamports) | ||
require.Equal(r, senderBefore.Value.Lamports+withdrawAmount.Uint64()/2, sender.Value.Lamports) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.