-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implementation of Solana restricted address (#2795)
* initiate impl of Solana restricted address * add changelog entry * doudle check no cctx is increated for restricted inbound * rename poste2e_checker.go as require.go
- Loading branch information
1 parent
d210011
commit b251df6
Showing
21 changed files
with
283 additions
and
49 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
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,28 @@ | ||
package e2etests | ||
|
||
import ( | ||
ethcommon "github.com/ethereum/go-ethereum/common" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/zeta-chain/node/e2e/runner" | ||
"github.com/zeta-chain/node/e2e/utils" | ||
) | ||
|
||
func TestSolanaDepositRestricted(r *runner.E2ERunner, args []string) { | ||
require.Len(r, args, 2) | ||
|
||
// parse restricted address | ||
receiverRestricted := ethcommon.HexToAddress(args[0]) | ||
|
||
// parse deposit amount (in lamports) | ||
depositAmount := parseBigInt(r, args[1]) | ||
|
||
// execute the deposit transaction | ||
sig := r.SOLDepositAndCall(nil, receiverRestricted, depositAmount, nil) | ||
|
||
// wait for 5 zeta blocks | ||
r.WaitForBlocks(5) | ||
|
||
// no cctx should be created | ||
utils.EnsureNoCctxMinedByInboundHash(r.Ctx, sig.String(), r.CctxClient) | ||
} |
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,36 @@ | ||
package e2etests | ||
|
||
import ( | ||
"fmt" | ||
"math/big" | ||
|
||
"github.com/gagliardetto/solana-go" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/zeta-chain/node/e2e/runner" | ||
"github.com/zeta-chain/node/pkg/chains" | ||
) | ||
|
||
func TestSolanaWithdrawRestricted(r *runner.E2ERunner, args []string) { | ||
require.Len(r, args, 2) | ||
|
||
// parse restricted address | ||
receiverRestricted, err := chains.DecodeSolanaWalletAddress(args[0]) | ||
require.NoError(r, err, fmt.Sprintf("unable to decode solana wallet address: %s", args[0])) | ||
|
||
// parse withdraw amount (in lamports), approve amount is 1 SOL | ||
approvedAmount := new(big.Int).SetUint64(solana.LAMPORTS_PER_SOL) | ||
withdrawAmount := parseBigInt(r, args[1]) | ||
require.Equal( | ||
r, | ||
-1, | ||
withdrawAmount.Cmp(approvedAmount), | ||
"Withdrawal amount must be less than the approved amount (1e9).", | ||
) | ||
|
||
// withdraw | ||
cctx := r.WithdrawSOLZRC20(receiverRestricted, withdrawAmount, approvedAmount) | ||
|
||
// the cctx should be cancelled with zero value | ||
verifySolanaWithdrawalAmountFromCCTX(r, cctx, 0) | ||
} |
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,61 @@ | ||
package runner | ||
|
||
import ( | ||
"fmt" | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
ethcommon "github.com/ethereum/go-ethereum/common" | ||
"github.com/stretchr/testify/require" | ||
"github.com/zeta-chain/protocol-contracts/v2/pkg/zrc20.sol" | ||
|
||
"github.com/zeta-chain/node/testutil/sample" | ||
crosschaintypes "github.com/zeta-chain/node/x/crosschain/types" | ||
) | ||
|
||
// EnsureNoTrackers ensures that there are no trackers left on zetacore | ||
func (r *E2ERunner) EnsureNoTrackers() { | ||
// get all trackers | ||
res, err := r.CctxClient.OutTxTrackerAll( | ||
r.Ctx, | ||
&crosschaintypes.QueryAllOutboundTrackerRequest{}, | ||
) | ||
require.NoError(r, err) | ||
require.Empty(r, res.OutboundTracker, "there should be no trackers at the end of the test") | ||
} | ||
|
||
// EnsureZeroBalanceAddressZEVM ensures that the balance of the address is zero in the ZEVM | ||
func (r *E2ERunner) EnsureZeroBalanceAddressZEVM() { | ||
restrictedAddress := ethcommon.HexToAddress(sample.RestrictedEVMAddressTest) | ||
|
||
// ensure ZETA balance is zero | ||
balance, err := r.WZeta.BalanceOf(&bind.CallOpts{}, restrictedAddress) | ||
require.NoError(r, err) | ||
require.Zero(r, balance.Cmp(big.NewInt(0)), "the wZETA balance of the address should be zero") | ||
|
||
// ensure ZRC20 ETH balance is zero | ||
ensureZRC20ZeroBalance(r, r.ETHZRC20, restrictedAddress) | ||
|
||
// ensure ZRC20 ERC20 balance is zero | ||
ensureZRC20ZeroBalance(r, r.ERC20ZRC20, restrictedAddress) | ||
|
||
// ensure ZRC20 BTC balance is zero | ||
ensureZRC20ZeroBalance(r, r.BTCZRC20, restrictedAddress) | ||
|
||
// ensure ZRC20 SOL balance is zero | ||
ensureZRC20ZeroBalance(r, r.SOLZRC20, restrictedAddress) | ||
} | ||
|
||
// ensureZRC20ZeroBalance ensures that the balance of the ZRC20 token is zero on given address | ||
func ensureZRC20ZeroBalance(r *E2ERunner, zrc20 *zrc20.ZRC20, address ethcommon.Address) { | ||
balance, err := zrc20.BalanceOf(&bind.CallOpts{}, address) | ||
require.NoError(r, err) | ||
|
||
zrc20Name, err := zrc20.Name(&bind.CallOpts{}) | ||
require.NoError(r, err) | ||
require.Zero( | ||
r, | ||
balance.Cmp(big.NewInt(0)), | ||
fmt.Sprintf("the balance of address %s should be zero on ZRC20: %s", address, zrc20Name), | ||
) | ||
} |
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.