Skip to content

Commit

Permalink
doudle check no cctx is increated for restricted inbound
Browse files Browse the repository at this point in the history
  • Loading branch information
ws4charlie committed Aug 29, 2024
1 parent 50ddd03 commit 77b768a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
13 changes: 12 additions & 1 deletion e2e/e2etests/test_erc20_deposit_restricted_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/zeta-chain/zetacore/e2e/runner"
"github.com/zeta-chain/zetacore/e2e/utils"
"github.com/zeta-chain/zetacore/testutil/sample"
)

Expand All @@ -15,5 +16,15 @@ func TestERC20DepositRestricted(r *runner.E2ERunner, args []string) {
amount := parseBigInt(r, args[0])

// deposit ERC20 to restricted address
r.DepositERC20WithAmountAndMessage(ethcommon.HexToAddress(sample.RestrictedEVMAddressTest), amount, []byte{})
txHash := r.DepositERC20WithAmountAndMessage(
ethcommon.HexToAddress(sample.RestrictedEVMAddressTest),
amount,
[]byte{},
)

// wait for 5 zeta blocks
r.WaitForBlocks(5)

// no cctx should be created
utils.EnsureNoCctxMinedByInboundHash(r.Ctx, txHash.String(), r.CctxClient)
}
9 changes: 8 additions & 1 deletion e2e/e2etests/test_solana_deposit_restricted_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/zeta-chain/zetacore/e2e/runner"
"github.com/zeta-chain/zetacore/e2e/utils"
)

func TestSolanaDepositRestricted(r *runner.E2ERunner, args []string) {
Expand All @@ -17,5 +18,11 @@ func TestSolanaDepositRestricted(r *runner.E2ERunner, args []string) {
depositAmount := parseBigInt(r, args[1])

// execute the deposit transaction
r.SOLDepositAndCall(nil, receiverRestricted, depositAmount, nil)
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)
}
9 changes: 8 additions & 1 deletion e2e/e2etests/test_zeta_deposit_restricted_address.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/zeta-chain/zetacore/e2e/runner"
"github.com/zeta-chain/zetacore/e2e/utils"
"github.com/zeta-chain/zetacore/testutil/sample"
)

Expand All @@ -15,5 +16,11 @@ func TestZetaDepositRestricted(r *runner.E2ERunner, args []string) {
amount := parseBigInt(r, args[0])

// Deposit amount to restricted address
r.DepositZetaWithAmount(ethcommon.HexToAddress(sample.RestrictedEVMAddressTest), amount)
txHash := r.DepositZetaWithAmount(ethcommon.HexToAddress(sample.RestrictedEVMAddressTest), amount)

// wait for 5 zeta blocks
r.WaitForBlocks(5)

// no cctx should be created
utils.EnsureNoCctxMinedByInboundHash(r.Ctx, txHash.String(), r.CctxClient)
}
14 changes: 14 additions & 0 deletions e2e/utils/zetacore.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ func WaitCctxMinedByInboundHash(
return cctxs[len(cctxs)-1]
}

// EnsureNoCctxMinedByInboundHash ensures no cctx is mined by inbound hash
func EnsureNoCctxMinedByInboundHash(
ctx context.Context,
inboundHash string,
client crosschaintypes.QueryClient,
) {
t := TestingFromContext(ctx)

// query cctx by inbound hash
in := &crosschaintypes.QueryGetInboundHashToCctxRequest{InboundHash: inboundHash}
_, err := client.InboundHashToCctx(ctx, in)
require.ErrorIs(t, err, status.Error(codes.NotFound, "not found"))
}

// WaitCctxsMinedByInboundHash waits until cctx is mined; returns the cctxIndex (the last one)
func WaitCctxsMinedByInboundHash(
ctx context.Context,
Expand Down

0 comments on commit 77b768a

Please sign in to comment.