-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5877780
commit b9d34ad
Showing
60 changed files
with
3,011 additions
and
474 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"os" | ||
) | ||
|
||
// solanaTestKey is a local test private key for Solana | ||
// TODO: use separate keys for each zetaclient in Solana E2E tests | ||
// https://github.com/zeta-chain/node/issues/2614 | ||
var solanaTestKey = []uint8{ | ||
199, 16, 63, 28, 125, 103, 131, 13, 6, 94, 68, 109, 13, 68, 132, 17, | ||
71, 33, 216, 51, 49, 103, 146, 241, 245, 162, 90, 228, 71, 177, 32, 199, | ||
31, 128, 124, 2, 23, 207, 48, 93, 141, 113, 91, 29, 196, 95, 24, 137, | ||
170, 194, 90, 4, 124, 113, 12, 222, 166, 209, 119, 19, 78, 20, 99, 5, | ||
} | ||
|
||
// createSolanaTestKeyFile creates a solana test key json file | ||
func createSolanaTestKeyFile(keyFile string) error { | ||
// marshal the byte array to JSON | ||
keyBytes, err := json.Marshal(solanaTestKey) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// create file (or overwrite if it already exists) | ||
// #nosec G304 -- for E2E testing purposes only | ||
file, err := os.Create(keyFile) | ||
if err != nil { | ||
return err | ||
} | ||
defer file.Close() | ||
|
||
// write the key bytes to the file | ||
_, err = file.Write(keyBytes) | ||
return err | ||
} |
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 |
---|---|---|
|
@@ -41,5 +41,3 @@ func CreateZetacoreClient(cfg config.Config, hotkeyPassword string, logger zerol | |
|
||
return client, nil | ||
} | ||
|
||
// TODO |
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
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,47 @@ | ||
package e2etests | ||
|
||
import ( | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
"github.com/gagliardetto/solana-go" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/zeta-chain/zetacore/e2e/runner" | ||
) | ||
|
||
func TestSolanaWithdraw(r *runner.E2ERunner, args []string) { | ||
require.Len(r, args, 1) | ||
|
||
// print balanceAfter of from address | ||
balanceBefore, err := r.SOLZRC20.BalanceOf(&bind.CallOpts{}, r.ZEVMAuth.From) | ||
require.NoError(r, err) | ||
r.Logger.Info("from address %s balance of SOL before: %d", r.ZEVMAuth.From, balanceBefore) | ||
|
||
// parse withdraw amount (in lamports), approve amount is 1 SOL | ||
approvedAmount := new(big.Int).SetUint64(solana.LAMPORTS_PER_SOL) | ||
// #nosec G115 e2e - always in range | ||
withdrawAmount := big.NewInt(int64(parseInt(r, args[0]))) | ||
require.Equal( | ||
r, | ||
-1, | ||
withdrawAmount.Cmp(approvedAmount), | ||
"Withdrawal amount must be less than the approved amount (1e9).", | ||
) | ||
|
||
// load deployer private key | ||
privkey, err := solana.PrivateKeyFromBase58(r.Account.SolanaPrivateKey.String()) | ||
require.NoError(r, err) | ||
|
||
// withdraw | ||
r.WithdrawSOLZRC20(privkey.PublicKey(), withdrawAmount, approvedAmount) | ||
|
||
// print balance of from address after withdraw | ||
balanceAfter, err := r.SOLZRC20.BalanceOf(&bind.CallOpts{}, r.ZEVMAuth.From) | ||
require.NoError(r, err) | ||
r.Logger.Info("from address %s balance of SOL after: %d", r.ZEVMAuth.From, 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") | ||
} |
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.