Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix and unit tests for query pending cctx within rate limit #2060

Merged
merged 41 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
8db24cc
initial commit of grpc pending cctx query with rate limiter
ws4charlie Apr 18, 2024
a873173
replace big.Float with sdk.Dec and update mock rate limiter flags
ws4charlie Apr 18, 2024
60cdbd0
split big loop into backwards loop and forwards loop to be more accurate
ws4charlie Apr 18, 2024
b888133
Merge branch 'develop' of https://github.com/zeta-chain/node into fea…
ws4charlie Apr 18, 2024
3f63f22
adjust zetaclient code to query pending cctx with rate limit
ws4charlie Apr 18, 2024
f0b0677
update change log and add one more rate limiter flag test
ws4charlie Apr 19, 2024
aab441e
use outboun amount for calculation
ws4charlie Apr 19, 2024
00ab5ac
some minimum code refactor
ws4charlie Apr 19, 2024
f31c988
created separate file for cctx query with rate limit
ws4charlie Apr 19, 2024
3cdf614
Merge branch 'develop' into feat-withdraw-rate-limit
ws4charlie Apr 19, 2024
6ad94af
improved a few error handlling
ws4charlie Apr 19, 2024
27e94a7
use old cctx query as fallback when rate limiter is disabled; some re…
ws4charlie Apr 19, 2024
0eb3b8a
fixed unit test compile
ws4charlie Apr 19, 2024
1568e44
Merge branch 'develop' into feat-withdraw-rate-limit
lumtis Apr 19, 2024
60e5dcc
added unit test for fallback query
ws4charlie Apr 20, 2024
101457c
added unit tests for cctx value conversion
ws4charlie Apr 20, 2024
7065d2e
added unit tests for cctx value conversion
ws4charlie Apr 20, 2024
874d5f3
add changelog entry
ws4charlie Apr 20, 2024
16955b8
added unit tests for query pending cctxs within rate limit
ws4charlie Apr 20, 2024
249bcaa
added total value in rate limiter window for monitoring purpose
ws4charlie Apr 20, 2024
dd950a8
Merge branch 'develop' into unit-test-rate-limit
lumtis Apr 22, 2024
7fe367f
Update x/crosschain/keeper/grpc_query_cctx_rate_limit.go
ws4charlie Apr 22, 2024
e5e4e28
change variable name fCoin to foreignCoin
ws4charlie Apr 22, 2024
5e28daf
Update x/fungible/keeper/foreign_coins.go
ws4charlie Apr 22, 2024
da27a84
Update x/crosschain/keeper/grpc_query_cctx_rate_limit_test.go
ws4charlie Apr 22, 2024
f9eed15
converted rate limiter query unit tests to table test
ws4charlie Apr 22, 2024
f40cf45
handle edge case when pending cctxs span wider block range than slidi…
ws4charlie Apr 24, 2024
578afcc
added zero rate check; added comment to make unit test clearer
ws4charlie Apr 24, 2024
fa24f32
added unit test and note for method GetAllForeignCoinMap
ws4charlie Apr 24, 2024
61627b1
treat Rate as average block rate; stop outbound when current rate lim…
ws4charlie Apr 25, 2024
daba269
add commented unit tests back
ws4charlie Apr 25, 2024
ec6aca8
Merge branch 'v16.0.0-rc' into unit-test-rate-limit
lumtis Apr 29, 2024
c011900
replace sdk.Dec with sdkmath.Int to represent cctx value in azeta
ws4charlie Apr 29, 2024
289ec62
test: disable header proof test in local upgrade test E2E test (#2051)
lumtis Apr 29, 2024
bd13759
test(e2e): add rate limiter admin E2E test (#2063)
lumtis Apr 29, 2024
4be83fb
removed incorrect Note
ws4charlie Apr 29, 2024
2a1433d
Merge branch 'v16.0.0-rc' into unit-test-rate-limit
ws4charlie Apr 29, 2024
23b7930
improved variable name
ws4charlie Apr 29, 2024
17b955e
Merge branch 'release/v16' into unit-test-rate-limit
lumtis Apr 30, 2024
7136f31
add E2E test for rate limiter gas and erc20
lumtis Apr 30, 2024
fd861d5
remove outdated comment
lumtis Apr 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
* [1985](https://github.com/zeta-chain/node/pull/1985) - improve fungible module coverage
* [1992](https://github.com/zeta-chain/node/pull/1992) - remove setupKeeper from crosschain module
* [2008](https://github.com/zeta-chain/node/pull/2008) - add test for connector bytecode update
* [2060](https://github.com/zeta-chain/node/pull/2060) - add unit test for rate limiter query

### Fixes

Expand Down
1 change: 1 addition & 0 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
}
if testAdmin {
eg.Go(adminTestRoutine(conf, deployerRunner, verbose,
e2etests.TestRateLimiterName,
e2etests.TestPauseZRC20Name,
e2etests.TestUpdateBytecodeZRC20Name,
e2etests.TestUpdateBytecodeConnectorName,
Expand Down
32 changes: 16 additions & 16 deletions contrib/localnet/orchestrator/start-zetae2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,36 @@ sleep 2
### Create the accounts and fund them with Ether on local Ethereum network

# unlock the deployer account
echo "funding deployer address 0xE5C5367B8224807Ac2207d350E60e1b6F27a7ecC with 100 Ether"
geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0xE5C5367B8224807Ac2207d350E60e1b6F27a7ecC", value: web3.toWei(100,"ether")})' attach http://eth:8545
echo "funding deployer address 0xE5C5367B8224807Ac2207d350E60e1b6F27a7ecC with 10000 Ether"
geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0xE5C5367B8224807Ac2207d350E60e1b6F27a7ecC", value: web3.toWei(10000,"ether")})' attach http://eth:8545

# unlock erc20 tester accounts
echo "funding deployer address 0x6F57D5E7c6DBb75e59F1524a3dE38Fc389ec5Fd6 with 100 Ether"
geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0x6F57D5E7c6DBb75e59F1524a3dE38Fc389ec5Fd6", value: web3.toWei(100,"ether")})' attach http://eth:8545
echo "funding deployer address 0x6F57D5E7c6DBb75e59F1524a3dE38Fc389ec5Fd6 with 10000 Ether"
geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0x6F57D5E7c6DBb75e59F1524a3dE38Fc389ec5Fd6", value: web3.toWei(10000,"ether")})' attach http://eth:8545

# unlock zeta tester accounts
echo "funding deployer address 0x5cC2fBb200A929B372e3016F1925DcF988E081fd with 100 Ether"
geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0x5cC2fBb200A929B372e3016F1925DcF988E081fd", value: web3.toWei(100,"ether")})' attach http://eth:8545
echo "funding deployer address 0x5cC2fBb200A929B372e3016F1925DcF988E081fd with 10000 Ether"
geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0x5cC2fBb200A929B372e3016F1925DcF988E081fd", value: web3.toWei(10000,"ether")})' attach http://eth:8545

# unlock bitcoin tester accounts
echo "funding deployer address 0x283d810090EdF4043E75247eAeBcE848806237fD with 100 Ether"
geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0x283d810090EdF4043E75247eAeBcE848806237fD", value: web3.toWei(100,"ether")})' attach http://eth:8545
echo "funding deployer address 0x283d810090EdF4043E75247eAeBcE848806237fD with 10000 Ether"
geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0x283d810090EdF4043E75247eAeBcE848806237fD", value: web3.toWei(10000,"ether")})' attach http://eth:8545

# unlock ethers tester accounts
echo "funding deployer address 0x8D47Db7390AC4D3D449Cc20D799ce4748F97619A with 100 Ether"
geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0x8D47Db7390AC4D3D449Cc20D799ce4748F97619A", value: web3.toWei(100,"ether")})' attach http://eth:8545
echo "funding deployer address 0x8D47Db7390AC4D3D449Cc20D799ce4748F97619A with 10000 Ether"
geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0x8D47Db7390AC4D3D449Cc20D799ce4748F97619A", value: web3.toWei(10000,"ether")})' attach http://eth:8545

# unlock miscellaneous tests accounts
echo "funding deployer address 0x90126d02E41c9eB2a10cfc43aAb3BD3460523Cdf with 100 Ether"
geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0x90126d02E41c9eB2a10cfc43aAb3BD3460523Cdf", value: web3.toWei(100,"ether")})' attach http://eth:8545
echo "funding deployer address 0x90126d02E41c9eB2a10cfc43aAb3BD3460523Cdf with 10000 Ether"
geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0x90126d02E41c9eB2a10cfc43aAb3BD3460523Cdf", value: web3.toWei(10000,"ether")})' attach http://eth:8545

# unlock admin erc20 tests accounts
echo "funding deployer address 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 with 100 Ether"
geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", value: web3.toWei(100,"ether")})' attach http://eth:8545
echo "funding deployer address 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 with 10000 Ether"
geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", value: web3.toWei(10000,"ether")})' attach http://eth:8545

# unlock the TSS account
echo "funding TSS address 0xF421292cb0d3c97b90EEEADfcD660B893592c6A2 with 100 Ether"
geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0xF421292cb0d3c97b90EEEADfcD660B893592c6A2", value: web3.toWei(100,"ether")})' attach http://eth:8545
echo "funding TSS address 0xF421292cb0d3c97b90EEEADfcD660B893592c6A2 with 10000 Ether"
geth --exec 'eth.sendTransaction({from: eth.coinbase, to: "0xF421292cb0d3c97b90EEEADfcD660B893592c6A2", value: web3.toWei(10000,"ether")})' attach http://eth:8545

### Run zetae2e command depending on the option passed

Expand Down
1 change: 1 addition & 0 deletions docs/cli/zetacored/zetacored_query_crosschain.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ zetacored query crosschain [flags]
* [zetacored query crosschain list-in-tx-tracker](zetacored_query_crosschain_list-in-tx-tracker.md) - shows a list of in tx tracker by chainId
* [zetacored query crosschain list-out-tx-tracker](zetacored_query_crosschain_list-out-tx-tracker.md) - list all OutTxTracker
* [zetacored query crosschain list-pending-cctx](zetacored_query_crosschain_list-pending-cctx.md) - shows pending CCTX
* [zetacored query crosschain list_pending_cctx_within_rate_limit](zetacored_query_crosschain_list_pending_cctx_within_rate_limit.md) - list all pending CCTX within rate limit
* [zetacored query crosschain show-cctx](zetacored_query_crosschain_show-cctx.md) - shows a CCTX
* [zetacored query crosschain show-gas-price](zetacored_query_crosschain_show-gas-price.md) - shows a gasPrice
* [zetacored query crosschain show-in-tx-hash-to-cctx](zetacored_query_crosschain_show-in-tx-hash-to-cctx.md) - shows a inTxHashToCctx
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# query crosschain list_pending_cctx_within_rate_limit

list all pending CCTX within rate limit

```
zetacored query crosschain list_pending_cctx_within_rate_limit [flags]
```

### Options

```
--grpc-addr string the gRPC endpoint to use for this chain
--grpc-insecure allow gRPC over insecure channels, if not TLS the server must use TLS
--height int Use a specific height to query state at (this can error if the node is pruning state)
-h, --help help for list_pending_cctx_within_rate_limit
--node string [host]:[port] to Tendermint RPC interface for this chain
-o, --output string Output format (text|json)
```

### Options inherited from parent commands

```
--chain-id string The network chain ID
--home string directory for config and data
--log_format string The logging format (json|plain)
--log_level string The logging level (trace|debug|info|warn|error|fatal|panic)
--trace print out full stack trace on errors
```

### SEE ALSO

* [zetacored query crosschain](zetacored_query_crosschain.md) - Querying commands for the crosschain module

5 changes: 5 additions & 0 deletions docs/openapi/openapi.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54013,6 +54013,11 @@ definitions:
total_pending:
type: string
format: uint64
current_withdraw_window:
type: string
format: int64
current_withdraw_rate:
type: string
rate_limit_exceeded:
type: boolean
crosschainQueryMessagePassingProtocolFeeResponse:
Expand Down
7 changes: 7 additions & 0 deletions e2e/e2etests/e2etests.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const (
TestPauseZRC20Name = "pause_zrc20"
TestUpdateBytecodeZRC20Name = "update_bytecode_zrc20"
TestUpdateBytecodeConnectorName = "update_bytecode_connector"
TestRateLimiterName = "rate_limiter"
)

// AllE2ETests is an ordered list of all e2e tests
Expand Down Expand Up @@ -386,6 +387,12 @@ var AllE2ETests = []runner.E2ETest{
[]runner.ArgDefinition{},
TestUpdateBytecodeConnector,
),
runner.NewE2ETest(
TestRateLimiterName,
"test sending cctxs with rate limiter enabled and show logs when processing cctxs",
[]runner.ArgDefinition{},
TestRateLimiter,
),
runner.NewE2ETest(
TestMessagePassingZEVMToEVMName,
"zevm -> evm message passing contract call",
Expand Down
22 changes: 2 additions & 20 deletions e2e/e2etests/test_erc20_withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,10 @@ func TestERC20Withdraw(r *runner.E2ERunner, args []string) {
r.Logger.Info("eth zrc20 approve receipt: status %d", receipt.Status)

// withdraw
tx, err = r.ERC20ZRC20.Withdraw(r.ZEVMAuth, r.DeployerAddress.Bytes(), withdrawalAmount)
if err != nil {
panic(err)
}
receipt = utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout)
r.Logger.Info("Receipt txhash %s status %d", receipt.TxHash, receipt.Status)
for _, log := range receipt.Logs {
event, err := r.ERC20ZRC20.ParseWithdrawal(*log)
if err != nil {
continue
}
r.Logger.Info(
" logs: from %s, to %x, value %d, gasfee %d",
event.From.Hex(),
event.To,
event.Value,
event.Gasfee,
)
}
tx = r.WithdrawERC20(withdrawalAmount)

// verify the withdraw value
cctx := utils.WaitCctxMinedByInTxHash(r.Ctx, receipt.TxHash.Hex(), r.CctxClient, r.Logger, r.CctxTimeout)
cctx := utils.WaitCctxMinedByInTxHash(r.Ctx, tx.Hash().Hex(), r.CctxClient, r.Logger, r.CctxTimeout)
verifyTransferAmountFromCCTX(r, cctx, withdrawalAmount.Int64())
}

Expand Down
4 changes: 2 additions & 2 deletions e2e/e2etests/test_eth_deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ func TestDepositEtherLiquidityCap(r *runner.E2ERunner, args []string) {
}

liquidityCap := math.NewUintFromBigInt(supply).Add(liquidityCapArg)
amountLessThanCap := liquidityCap.BigInt().Div(liquidityCap.BigInt(), big.NewInt(10)) // 1/10 of the cap
amountMoreThanCap := liquidityCap.BigInt().Mul(liquidityCap.BigInt(), big.NewInt(10)) // 10 times the cap
amountLessThanCap := liquidityCapArg.BigInt().Div(liquidityCapArg.BigInt(), big.NewInt(10)) // 1/10 of the cap
amountMoreThanCap := liquidityCapArg.BigInt().Mul(liquidityCapArg.BigInt(), big.NewInt(10)) // 10 times the cap
msg := fungibletypes.NewMsgUpdateZRC20LiquidityCap(
r.ZetaTxServer.GetAccountAddress(0),
r.ETHZRC20Addr.Hex(),
Expand Down
15 changes: 2 additions & 13 deletions e2e/e2etests/test_eth_withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,10 @@ func TestEtherWithdraw(r *runner.E2ERunner, args []string) {
r.Logger.EVMReceipt(*receipt, "approve")

// withdraw
tx, err = r.ETHZRC20.Withdraw(r.ZEVMAuth, r.DeployerAddress.Bytes(), withdrawalAmount)
if err != nil {
panic(err)
}
r.Logger.EVMTransaction(*tx, "withdraw")

receipt = utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout)
if receipt.Status == 0 {
panic("withdraw failed")
}
r.Logger.EVMReceipt(*receipt, "withdraw")
r.Logger.ZRC20Withdrawal(r.ETHZRC20, *receipt, "withdraw")
tx = r.WithdrawEther(withdrawalAmount)

// verify the withdraw value
cctx := utils.WaitCctxMinedByInTxHash(r.Ctx, receipt.TxHash.Hex(), r.CctxClient, r.Logger, r.CctxTimeout)
cctx := utils.WaitCctxMinedByInTxHash(r.Ctx, tx.Hash().Hex(), r.CctxClient, r.Logger, r.CctxTimeout)
r.Logger.CCTX(*cctx, "withdraw")
if cctx.CctxStatus.Status != crosschaintypes.CctxStatus_OutboundMined {
panic("cctx status is not outbound mined")
Expand Down
15 changes: 14 additions & 1 deletion e2e/e2etests/test_migrate_chain_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,20 @@ func TestMigrateChainSupport(r *runner.E2ERunner, _ []string) {
newRunner.WaitForMinedCCTX(txEtherDeposit)

// perform withdrawals on the new chain
TestZetaWithdraw(newRunner, []string{"10000000000000000000"})
amount := big.NewInt(0).Mul(big.NewInt(1e18), big.NewInt(10))
newRunner.DepositAndApproveWZeta(amount)
tx := newRunner.WithdrawZeta(amount, true)
cctx := utils.WaitCctxMinedByInTxHash(r.Ctx, tx.Hash().Hex(), r.CctxClient, r.Logger, r.CctxTimeout)
r.Logger.CCTX(*cctx, "zeta withdraw")
if cctx.CctxStatus.Status != crosschaintypes.CctxStatus_OutboundMined {
panic(fmt.Errorf(
"expected cctx status to be %s; got %s, message %s",
crosschaintypes.CctxStatus_OutboundMined,
cctx.CctxStatus.Status.String(),
cctx.CctxStatus.StatusMessage,
))
}

TestEtherWithdraw(newRunner, []string{"50000000000000000"})

// finally try to deposit Zeta back
Expand Down
Loading
Loading