-
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.
initiate impl of Solana restricted address
- Loading branch information
1 parent
26c4fb1
commit 94163a1
Showing
19 changed files
with
243 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package e2etests | ||
|
||
import ( | ||
ethcommon "github.com/ethereum/go-ethereum/common" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/zeta-chain/zetacore/e2e/runner" | ||
) | ||
|
||
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 | ||
r.SOLDepositAndCall(nil, receiverRestricted, depositAmount, nil) | ||
} |
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/zetacore/e2e/runner" | ||
"github.com/zeta-chain/zetacore/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/zetacore/testutil/sample" | ||
crosschaintypes "github.com/zeta-chain/zetacore/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") | ||
} | ||
|
||
// EnsureZeroBalanceOnRestrictedAddress ensures that the balance of the restricted address is zero | ||
func (r *E2ERunner) EnsureZeroBalanceOnRestrictedAddress() { | ||
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 restricted 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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.