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: add tests for most used admin transactions #2473

Merged
merged 18 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
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
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,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 @@ -289,6 +289,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
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
* [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

kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -94,12 +94,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 @@ -533,6 +534,12 @@ var AllE2ETests = []runner.E2ETest{
[]runner.ArgDefinition{},
TestRateLimiter,
),
runner.NewE2ETest(
TestCriticalAdminTransactionsName,
"test critical admin transactions",
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
[]runner.ArgDefinition{},
TestAdminTransactions,
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
),
/*
Special tests
*/
Expand Down
28 changes: 28 additions & 0 deletions e2e/e2etests/helpers.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,49 @@
package e2etests

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

"github.com/btcsuite/btcd/btcjson"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcutil"
"github.com/cenkalti/backoff/v4"
ethcommon "github.com/ethereum/go-ethereum/common"
"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/retry"
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
)

func WaitForBlocks(r *runner.E2ERunner, n int64) {
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
height, err := r.CctxClient.LastZetaHeight(r.Ctx, &crosschaintypes.QueryLastZetaHeightRequest{})
if err != nil {
return

Check warning on line 26 in e2e/e2etests/helpers.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/helpers.go#L23-L26

Added lines #L23 - L26 were not covered by tests
}
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
call := func() error {
return retry.Retry(waitForBlock(r, height.Height+n))

Check warning on line 29 in e2e/e2etests/helpers.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/helpers.go#L28-L29

Added lines #L28 - L29 were not covered by tests
}

bo := backoff.NewConstantBackOff(time.Second * 5)
err = retry.DoWithBackoff(call, bo)
require.NoError(r, err, "failed to wait for %d blocks", n)

Check warning on line 34 in e2e/e2etests/helpers.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/helpers.go#L32-L34

Added lines #L32 - L34 were not covered by tests
}
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
func waitForBlock(r *runner.E2ERunner, n int64) error {
height, err := r.CctxClient.LastZetaHeight(r.Ctx, &crosschaintypes.QueryLastZetaHeightRequest{})
if err != nil {
return err

Check warning on line 39 in e2e/e2etests/helpers.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/helpers.go#L36-L39

Added lines #L36 - L39 were not covered by tests
}
if height.Height < n {
return fmt.Errorf("waiting for %d blocks, current height %d", n, height.Height)

Check warning on line 42 in e2e/e2etests/helpers.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/helpers.go#L41-L42

Added lines #L41 - L42 were not covered by tests
}
return nil

Check warning on line 44 in e2e/e2etests/helpers.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/helpers.go#L44

Added line #L44 was not covered by tests
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
}

func withdrawBTCZRC20(r *runner.E2ERunner, to btcutil.Address, amount *big.Int) *btcjson.TxRawResult {
tx, err := r.BTCZRC20.Approve(
r.ZEVMAuth,
Expand Down
87 changes: 87 additions & 0 deletions e2e/e2etests/test_admin_transactions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
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"
)

func TestAdminTransactions(r *runner.E2ERunner, _ []string) {
TestAddToInboundTracker(r)
TestUpdateGasPriceIncreaseFlags(r)

Check warning on line 17 in e2e/e2etests/test_admin_transactions.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/test_admin_transactions.go#L15-L17

Added lines #L15 - L17 were not covered by tests
}

func TestUpdateGasPriceIncreaseFlags(r *runner.E2ERunner) {
defaultFlags := observertypes.DefaultGasPriceIncreaseFlags
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
msgGasPriceFlags := observertypes.NewMsgUpdateGasPriceIncreaseFlags(
r.ZetaTxServer.MustGetAccountAddressFromName(utils.OperationalPolicyName),
defaultFlags,
)
_, err := r.ZetaTxServer.BroadcastTx(utils.OperationalPolicyName, msgGasPriceFlags)
require.NoError(r, err)

Check warning on line 27 in e2e/e2etests/test_admin_transactions.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/test_admin_transactions.go#L20-L27

Added lines #L20 - L27 were not covered by tests

defaultFlagsUpdated := defaultFlags
defaultFlagsUpdated.EpochLength = defaultFlags.EpochLength + 1

Check warning on line 30 in e2e/e2etests/test_admin_transactions.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/test_admin_transactions.go#L29-L30

Added lines #L29 - L30 were not covered by tests

msgGasPriceFlags = observertypes.NewMsgUpdateGasPriceIncreaseFlags(
r.ZetaTxServer.MustGetAccountAddressFromName(utils.OperationalPolicyName),
defaultFlagsUpdated,
)

Check warning on line 35 in e2e/e2etests/test_admin_transactions.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/test_admin_transactions.go#L32-L35

Added lines #L32 - L35 were not covered by tests

_, err = r.ZetaTxServer.BroadcastTx(utils.OperationalPolicyName, msgGasPriceFlags)
require.NoError(r, err)

Check warning on line 38 in e2e/e2etests/test_admin_transactions.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/test_admin_transactions.go#L37-L38

Added lines #L37 - L38 were not covered by tests

WaitForBlocks(r, 1)

Check warning on line 40 in e2e/e2etests/test_admin_transactions.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/test_admin_transactions.go#L40

Added line #L40 was not covered by tests

flags, err := r.ObserverClient.CrosschainFlags(r.Ctx, &observertypes.QueryGetCrosschainFlagsRequest{})
require.NoError(r, err)

Check warning on line 43 in e2e/e2etests/test_admin_transactions.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/test_admin_transactions.go#L42-L43

Added lines #L42 - L43 were not covered by tests

require.Equal(r, defaultFlagsUpdated.EpochLength, flags.CrosschainFlags.GasPriceIncreaseFlags.EpochLength)

Check warning on line 45 in e2e/e2etests/test_admin_transactions.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/test_admin_transactions.go#L45

Added line #L45 was not covered by tests
}

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)

Check warning on line 58 in e2e/e2etests/test_admin_transactions.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/test_admin_transactions.go#L48-L58

Added lines #L48 - L58 were not covered by tests

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

Check warning on line 65 in e2e/e2etests/test_admin_transactions.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/test_admin_transactions.go#L60-L65

Added lines #L60 - L65 were not covered by tests

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

Check warning on line 68 in e2e/e2etests/test_admin_transactions.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/test_admin_transactions.go#L67-L68

Added lines #L67 - L68 were not covered by tests

WaitForBlocks(r, 1)

Check warning on line 70 in e2e/e2etests/test_admin_transactions.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/test_admin_transactions.go#L70

Added line #L70 was not covered by tests

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)

Check warning on line 78 in e2e/e2etests/test_admin_transactions.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/test_admin_transactions.go#L72-L78

Added lines #L72 - L78 were not covered by tests

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)

Check warning on line 86 in e2e/e2etests/test_admin_transactions.go

View check run for this annotation

Codecov / codecov/patch

e2e/e2etests/test_admin_transactions.go#L80-L86

Added lines #L80 - L86 were not covered by tests
}
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
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
26 changes: 26 additions & 0 deletions x/crosschain/client/cli/query_inbound_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,32 @@ import (
"github.com/zeta-chain/zetacore/x/crosschain/types"
)

func CmdShowInboundTracker() *cobra.Command {
cmd := &cobra.Command{
Use: "show-inbound-tracker [chainID] [txHash]",
Short: "shows an inbound tracker by chainID and txHash",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)
argChain, err := strconv.ParseInt(args[0], 10, 64)
if err != nil {
return err
kingpinXD marked this conversation as resolved.
Show resolved Hide resolved
}
params := &types.QueryInboundTrackerRequest{
ChainId: argChain,
TxHash: args[1],
}
res, err := queryClient.InboundTracker(context.Background(), params)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}
func CmdListInboundTrackerByChain() *cobra.Command {
cmd := &cobra.Command{
Use: "list-inbound-tracker [chainId]",
Expand Down
Loading
Loading