Skip to content

Commit

Permalink
test: add tests for most used admin transactions (#2473)
Browse files Browse the repository at this point in the history
* add policy accounts

* seperate policy accounts for each policy type

* remove fungible admin and add changelog

* generate files

* add test for add inbound tracker

* add sub function

* add UpdateGasPriceIncreaseFlags

* add changelog

* rename proto files

* use retry package

* rebase develop

* use constant backoff

* generate files

* resolve comments 2

* generate
  • Loading branch information
kingpinXD committed Jul 23, 2024
1 parent fbc5400 commit 8ebae66
Show file tree
Hide file tree
Showing 16 changed files with 1,051 additions and 152 deletions.
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
* [2549](https://github.com/zeta-chain/node/pull/2459) - add separate accounts for each policy in e2e tests
* [2415](https://github.com/zeta-chain/node/pull/2415) - add e2e test for upgrade and test admin functionalities
* [2440](https://github.com/zeta-chain/node/pull/2440) - Add e2e test for TSS migration

* [2473](https://github.com/zeta-chain/node/pull/2473) - add e2e tests for most used admin transactions

### 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 @@ -297,6 +297,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
e2etests.TestUpdateBytecodeZRC20Name,
e2etests.TestUpdateBytecodeConnectorName,
e2etests.TestDepositEtherLiquidityCapName,
e2etests.TestCriticalAdminTransactionsName,

// TestMigrateChainSupportName tests EVM chain migration. Currently this test doesn't work with Anvil because pre-EIP1559 txs are not supported
// See issue below for details
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 @@ -40,6 +40,7 @@ zetacored query crosschain [flags]
* [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-inbound-hash-to-cctx](zetacored_query_crosschain_show-inbound-hash-to-cctx.md) - shows a inboundHashToCctx
* [zetacored query crosschain show-inbound-tracker](zetacored_query_crosschain_show-inbound-tracker.md) - shows an inbound tracker by chainID and txHash
* [zetacored query crosschain show-outbound-tracker](zetacored_query_crosschain_show-outbound-tracker.md) - shows an outbound tracker
* [zetacored query crosschain show-rate-limiter-flags](zetacored_query_crosschain_show-rate-limiter-flags.md) - shows the rate limiter flags

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# query crosschain show-inbound-tracker

shows an inbound tracker by chainID and txHash

```
zetacored query crosschain show-inbound-tracker [chainID] [txHash] [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 show-inbound-tracker
--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)
--log_no_color Disable colored logs
--trace print out full stack trace on errors
```

### SEE ALSO

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

29 changes: 29 additions & 0 deletions docs/openapi/openapi.swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28846,6 +28846,30 @@ paths:
type: string
tags:
- Query
/zeta-chain/crosschain/inboundTracker/{chain_id}/{tx_hash}:
get:
operationId: Query_InboundTracker
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/crosschainQueryInboundTrackerResponse'
default:
description: An unexpected error response.
schema:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: chain_id
in: path
required: true
type: string
format: int64
- name: tx_hash
in: path
required: true
type: string
tags:
- Query
/zeta-chain/crosschain/inboundTrackerByChain/{chain_id}:
get:
operationId: Query_InboundTrackerAllByChain
Expand Down Expand Up @@ -57397,6 +57421,11 @@ definitions:
items:
type: object
$ref: '#/definitions/crosschainCrossChainTx'
crosschainQueryInboundTrackerResponse:
type: object
properties:
inbound_tracker:
$ref: '#/definitions/crosschainInboundTracker'
crosschainQueryLastZetaHeightResponse:
type: object
properties:
Expand Down
19 changes: 13 additions & 6 deletions e2e/e2etests/e2etests.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,13 @@ const (
Admin tests
Test admin functionalities
*/
TestDepositEtherLiquidityCapName = "deposit_eth_liquidity_cap"
TestMigrateChainSupportName = "migrate_chain_support"
TestPauseZRC20Name = "pause_zrc20"
TestUpdateBytecodeZRC20Name = "update_bytecode_zrc20"
TestUpdateBytecodeConnectorName = "update_bytecode_connector"
TestRateLimiterName = "rate_limiter"
TestDepositEtherLiquidityCapName = "deposit_eth_liquidity_cap"
TestMigrateChainSupportName = "migrate_chain_support"
TestPauseZRC20Name = "pause_zrc20"
TestUpdateBytecodeZRC20Name = "update_bytecode_zrc20"
TestUpdateBytecodeConnectorName = "update_bytecode_connector"
TestRateLimiterName = "rate_limiter"
TestCriticalAdminTransactionsName = "critical_admin_transactions"

TestMigrateTSSName = "migrate_TSS"

Expand Down Expand Up @@ -549,6 +550,12 @@ var AllE2ETests = []runner.E2ETest{
[]runner.ArgDefinition{},
TestRateLimiter,
),
runner.NewE2ETest(
TestCriticalAdminTransactionsName,
"test critical admin transactions",
[]runner.ArgDefinition{},
TestCriticalAdminTransactions,
),
/*
Special tests
*/
Expand Down
105 changes: 105 additions & 0 deletions e2e/e2etests/test_admin_transactions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package e2etests

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/pkg/chains"
"github.com/zeta-chain/zetacore/pkg/coin"
"github.com/zeta-chain/zetacore/testutil/sample"
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
)

// TestCriticalAdminTransactions tests critical admin transactions that are the most used on mainnet .
// The complete list is
// MsgUpdateChainParams
// MsgRefundAbortedCCTX
// MsgEnableCCTX
// MsgDisableCCTX
// MsgUpdateGasPriceIncreaseFlags
// MsgAddInboundTracker
// MsgUpdateZRC20LiquidityCap
// MsgDeploySystemContracts
// MsgWhitelistERC20
// MsgPauseZRC20
// MsgMigrateTssFunds
// MsgUpdateTssAddress
//
// However, the transactions other than `AddToInboundTracker` and `UpdateGasPriceIncreaseFlags` have already been used in other tests.
func TestCriticalAdminTransactions(r *runner.E2ERunner, _ []string) {
TestAddToInboundTracker(r)
TestUpdateGasPriceIncreaseFlags(r)
}

func TestUpdateGasPriceIncreaseFlags(r *runner.E2ERunner) {
// Set default flags on zetacore
defaultFlags := observertypes.DefaultGasPriceIncreaseFlags
msgGasPriceFlags := observertypes.NewMsgUpdateGasPriceIncreaseFlags(
r.ZetaTxServer.MustGetAccountAddressFromName(utils.OperationalPolicyName),
defaultFlags,
)
_, err := r.ZetaTxServer.BroadcastTx(utils.OperationalPolicyName, msgGasPriceFlags)
require.NoError(r, err)

// create a new set of flag values by incrementing the epoch length by 1
defaultFlagsUpdated := defaultFlags
defaultFlagsUpdated.EpochLength = defaultFlags.EpochLength + 1

// Update the flags on zetacore with the new values
msgGasPriceFlags = observertypes.NewMsgUpdateGasPriceIncreaseFlags(
r.ZetaTxServer.MustGetAccountAddressFromName(utils.OperationalPolicyName),
defaultFlagsUpdated,
)
_, err = r.ZetaTxServer.BroadcastTx(utils.OperationalPolicyName, msgGasPriceFlags)
require.NoError(r, err)

r.WaitForBlocks(1)

// Verify that the flags have been updated
flags, err := r.ObserverClient.CrosschainFlags(r.Ctx, &observertypes.QueryGetCrosschainFlagsRequest{})
require.NoError(r, err)
require.Equal(r, defaultFlagsUpdated.EpochLength, flags.CrosschainFlags.GasPriceIncreaseFlags.EpochLength)
}

func TestAddToInboundTracker(r *runner.E2ERunner) {
chainEth := chains.GoerliLocalnet
chainBtc := chains.BitcoinRegtest
msgEth := crosschaintypes.NewMsgAddInboundTracker(
r.ZetaTxServer.MustGetAccountAddressFromName(utils.EmergencyPolicyName),
chainEth.ChainId,
coin.CoinType_Gas,
sample.Hash().Hex(),
)
_, err := r.ZetaTxServer.BroadcastTx(utils.EmergencyPolicyName, msgEth)
require.NoError(r, err)

msgBtc := crosschaintypes.NewMsgAddInboundTracker(
r.ZetaTxServer.MustGetAccountAddressFromName(utils.EmergencyPolicyName),
chainBtc.ChainId,
coin.CoinType_Gas,
sample.BtcHash().String(),
)

_, err = r.ZetaTxServer.BroadcastTx(utils.EmergencyPolicyName, msgBtc)
require.NoError(r, err)

r.WaitForBlocks(1)

tracker, err := r.CctxClient.InboundTracker(r.Ctx, &crosschaintypes.QueryInboundTrackerRequest{
ChainId: msgEth.ChainId,
TxHash: msgEth.TxHash,
})
require.NoError(r, err)
require.NotNil(r, tracker)
require.Equal(r, msgEth.TxHash, tracker.InboundTracker.TxHash)

tracker, err = r.CctxClient.InboundTracker(r.Ctx, &crosschaintypes.QueryInboundTrackerRequest{
ChainId: msgBtc.ChainId,
TxHash: msgBtc.TxHash,
})
require.NoError(r, err)
require.NotNil(r, tracker)
require.Equal(r, msgBtc.TxHash, tracker.InboundTracker.TxHash)
}
29 changes: 29 additions & 0 deletions e2e/runner/zeta.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,47 @@
package runner

import (
"fmt"
"math/big"
"time"

"github.com/cenkalti/backoff/v4"
ethcommon "github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/stretchr/testify/require"
zetaconnectoreth "github.com/zeta-chain/protocol-contracts/pkg/contracts/evm/zetaconnector.eth.sol"
connectorzevm "github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/zetaconnectorzevm.sol"

"github.com/zeta-chain/zetacore/e2e/utils"
"github.com/zeta-chain/zetacore/pkg/retry"
"github.com/zeta-chain/zetacore/x/crosschain/types"
)

func (r *E2ERunner) WaitForBlocks(n int64) {
height, err := r.CctxClient.LastZetaHeight(r.Ctx, &types.QueryLastZetaHeightRequest{})
if err != nil {
return
}
call := func() error {
return retry.Retry(r.waitForBlock(height.Height + n))
}

bo := backoff.NewConstantBackOff(time.Second * 5)
boWithMaxRetries := backoff.WithMaxRetries(bo, 10)
err = retry.DoWithBackoff(call, boWithMaxRetries)
require.NoError(r, err, "failed to wait for %d blocks", n)
}
func (r *E2ERunner) waitForBlock(n int64) error {
height, err := r.CctxClient.LastZetaHeight(r.Ctx, &types.QueryLastZetaHeightRequest{})
if err != nil {
return err
}
if height.Height < n {
return fmt.Errorf("waiting for %d blocks, current height %d", n, height.Height)
}
return nil
}

// WaitForTxReceiptOnZEVM waits for a tx receipt on ZEVM
func (r *E2ERunner) WaitForTxReceiptOnZEVM(tx *ethtypes.Transaction) {
r.Lock()
Expand Down
15 changes: 15 additions & 0 deletions proto/zetachain/zetacore/crosschain/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ service Query {
option (google.api.http).get = "/zeta-chain/crosschain/inboundTrackers";
}

rpc InboundTracker(QueryInboundTrackerRequest)
returns (QueryInboundTrackerResponse) {
option (google.api.http).get =
"/zeta-chain/crosschain/inboundTracker/{chain_id}/{tx_hash}";
}

// Queries a InboundHashToCctx by index.
rpc InboundHashToCctx(QueryGetInboundHashToCctxRequest)
returns (QueryGetInboundHashToCctxResponse) {
Expand Down Expand Up @@ -383,3 +389,12 @@ message QueryRateLimiterFlagsRequest {}
message QueryRateLimiterFlagsResponse {
RateLimiterFlags rateLimiterFlags = 1 [ (gogoproto.nullable) = false ];
}

message QueryInboundTrackerRequest {
int64 chain_id = 1;
string tx_hash = 2;
}

message QueryInboundTrackerResponse {
InboundTracker inbound_tracker = 1 [ (gogoproto.nullable) = false ];
}
53 changes: 53 additions & 0 deletions typescript/zetachain/zetacore/crosschain/query_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1214,3 +1214,56 @@ export declare class QueryRateLimiterFlagsResponse extends Message<QueryRateLimi
static equals(a: QueryRateLimiterFlagsResponse | PlainMessage<QueryRateLimiterFlagsResponse> | undefined, b: QueryRateLimiterFlagsResponse | PlainMessage<QueryRateLimiterFlagsResponse> | undefined): boolean;
}

/**
* @generated from message zetachain.zetacore.crosschain.QueryInboundTrackerRequest
*/
export declare class QueryInboundTrackerRequest extends Message<QueryInboundTrackerRequest> {
/**
* @generated from field: int64 chain_id = 1;
*/
chainId: bigint;

/**
* @generated from field: string tx_hash = 2;
*/
txHash: string;

constructor(data?: PartialMessage<QueryInboundTrackerRequest>);

static readonly runtime: typeof proto3;
static readonly typeName = "zetachain.zetacore.crosschain.QueryInboundTrackerRequest";
static readonly fields: FieldList;

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): QueryInboundTrackerRequest;

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): QueryInboundTrackerRequest;

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): QueryInboundTrackerRequest;

static equals(a: QueryInboundTrackerRequest | PlainMessage<QueryInboundTrackerRequest> | undefined, b: QueryInboundTrackerRequest | PlainMessage<QueryInboundTrackerRequest> | undefined): boolean;
}

/**
* @generated from message zetachain.zetacore.crosschain.QueryInboundTrackerResponse
*/
export declare class QueryInboundTrackerResponse extends Message<QueryInboundTrackerResponse> {
/**
* @generated from field: zetachain.zetacore.crosschain.InboundTracker inbound_tracker = 1;
*/
inboundTracker?: InboundTracker;

constructor(data?: PartialMessage<QueryInboundTrackerResponse>);

static readonly runtime: typeof proto3;
static readonly typeName = "zetachain.zetacore.crosschain.QueryInboundTrackerResponse";
static readonly fields: FieldList;

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): QueryInboundTrackerResponse;

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): QueryInboundTrackerResponse;

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): QueryInboundTrackerResponse;

static equals(a: QueryInboundTrackerResponse | PlainMessage<QueryInboundTrackerResponse> | undefined, b: QueryInboundTrackerResponse | PlainMessage<QueryInboundTrackerResponse> | undefined): boolean;
}

1 change: 1 addition & 0 deletions x/crosschain/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func GetQueryCmd(_ string) *cobra.Command {
CmdPendingCctx(),
CmdListInboundTrackerByChain(),
CmdListInboundTrackers(),
CmdShowInboundTracker(),
CmdGetZetaAccounting(),
CmdListPendingCCTXWithinRateLimit(),

Expand Down
Loading

0 comments on commit 8ebae66

Please sign in to comment.