From 43ef6c8a1b0a5a9bf0294b683105fa8bdd099a79 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Sat, 27 Jan 2024 16:57:28 -0500 Subject: [PATCH 01/13] add admin to init.sh --- standalone-network/init.sh | 4 +++- standalone-network/run.sh | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/standalone-network/init.sh b/standalone-network/init.sh index ca932c2a21..6a1d221f05 100755 --- a/standalone-network/init.sh +++ b/standalone-network/init.sh @@ -16,7 +16,7 @@ echo "lounge supply patch festival retire duck foster decline theme horror decli echo "debris dumb among crew celery derive judge spoon road oyster dad panic adult song attack net pole merge mystery pig actual penalty neither peasant"| zetacored keys add executer_mario --algo=secp256k1 --recover --keyring-backend=$KEYRING zetacored init Zetanode-Localnet --chain-id=$CHAINID - +zetaAddress=$(zetacored keys show zeta -a --keyring-backend=test) #Set config to use azeta cat $HOME/.zetacored/config/genesis.json | jq '.app_state["staking"]["params"]["bond_denom"]="azeta"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json cat $HOME/.zetacored/config/genesis.json | jq '.app_state["crisis"]["constant_fee"]["denom"]="azeta"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json @@ -24,6 +24,8 @@ cat $HOME/.zetacored/config/genesis.json | jq '.app_state["gov"]["deposit_params cat $HOME/.zetacored/config/genesis.json | jq '.app_state["mint"]["params"]["mint_denom"]="azeta"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json cat $HOME/.zetacored/config/genesis.json | jq '.app_state["evm"]["params"]["evm_denom"]="azeta"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json cat $HOME/.zetacored/config/genesis.json | jq '.consensus_params["block"]["max_gas"]="10000000"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json +cat $HOME/.zetacored/config/genesis.json | jq '.app_state["observer"]["params"]["admin_policy"][1]["address"]="zeta13c7p3xrhd6q2rx3h235jpt8pjdwvacyw6twpax"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json +cat $HOME/.zetacored/config/genesis.json | jq '.app_state["observer"]["params"]["admin_policy"][0]["address"]="zeta13c7p3xrhd6q2rx3h235jpt8pjdwvacyw6twpax"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json contents="$(jq '.app_state.gov.voting_params.voting_period = "10s"' $DAEMON_HOME/config/genesis.json)" && \ echo "${contents}" > $DAEMON_HOME/config/genesis.json sed -i '/\[api\]/,+3 s/enable = false/enable = true/' ~/.zetacored/config/app.toml diff --git a/standalone-network/run.sh b/standalone-network/run.sh index 42b76cfce0..594478be42 100755 --- a/standalone-network/run.sh +++ b/standalone-network/run.sh @@ -32,5 +32,8 @@ zetacored start --trace \ #echo "--> Submitting vote for proposal" #sleep 7 #zetacored tx gov vote 1 yes --from $signer --keyring-backend $KEYRING --chain-id $CHAINID --yes --fees=40azeta --broadcast-mode=block +sleep 7 +zetacored tx fungible deploy-system-contracts --from zeta --gas=auto --gas-prices=10000000000azeta --gas-adjustment=1.5 --chain-id=localnet_101-1 --keyring-backend=test -y --broadcast-mode=block + tail -f ~/.zetacored/zetacored.log From 10c55fa7455e36b7826a64e8631fcb6960a4dada Mon Sep 17 00:00:00 2001 From: Tanmay Date: Sat, 27 Jan 2024 17:22:05 -0500 Subject: [PATCH 02/13] add changelog entry --- changelog.md | 1 + standalone-network/init.sh | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 1adfa29044..395f354f91 100644 --- a/changelog.md +++ b/changelog.md @@ -25,6 +25,7 @@ * [1585](https://github.com/zeta-chain/node/pull/1585) - Updated release instructions * [1615](https://github.com/zeta-chain/node/pull/1615) - Add upgrade handler for version v12.1.0 +* [1652](https://github.com/zeta-chain/node/pull/1652) - add admin to init script in standalone network ### Features diff --git a/standalone-network/init.sh b/standalone-network/init.sh index 6a1d221f05..af98c18083 100755 --- a/standalone-network/init.sh +++ b/standalone-network/init.sh @@ -16,7 +16,6 @@ echo "lounge supply patch festival retire duck foster decline theme horror decli echo "debris dumb among crew celery derive judge spoon road oyster dad panic adult song attack net pole merge mystery pig actual penalty neither peasant"| zetacored keys add executer_mario --algo=secp256k1 --recover --keyring-backend=$KEYRING zetacored init Zetanode-Localnet --chain-id=$CHAINID -zetaAddress=$(zetacored keys show zeta -a --keyring-backend=test) #Set config to use azeta cat $HOME/.zetacored/config/genesis.json | jq '.app_state["staking"]["params"]["bond_denom"]="azeta"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json cat $HOME/.zetacored/config/genesis.json | jq '.app_state["crisis"]["constant_fee"]["denom"]="azeta"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json From 161e7ada17a2bb3c0076d9d130a31283bb575243 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Fri, 2 Feb 2024 13:16:45 -0500 Subject: [PATCH 03/13] remove standalone network --- standalone-network/add-emissions.sh | 23 ---- standalone-network/add-observer.sh | 14 --- standalone-network/authz/commands.sh | 10 -- standalone-network/authz/tx.json | 35 ------ standalone-network/cctx/cctx-creator-gas.sh | 16 --- .../cctx/cctx-creator-goerili.sh | 65 ---------- standalone-network/cctx/cctx-creator-zeta.sh | 16 --- standalone-network/cctx_authz/commands.sh | 31 ----- .../cctx_authz/gas_price_voter_zeta.json | 34 ----- .../cctx_authz/mario_inbound_vote.json | 42 ------- .../cctx_authz/mario_outbound_vote.json | 38 ------ .../cctx_authz/nonce_voter_zeta.json | 32 ----- .../cctx_authz/zeta_inbound_vote.json | 42 ------- .../cctx_authz/zeta_outbound_vote.json | 38 ------ standalone-network/change-observer-params.sh | 2 - standalone-network/evm-init | 104 --------------- standalone-network/gov/gov.sh | 0 .../gov_observer_params_supported_chains.json | 58 --------- standalone-network/group/add-observer.json | 28 ----- standalone-network/group/group.sh | 11 -- standalone-network/group/members-updated.json | 14 --- standalone-network/group/members.json | 14 --- standalone-network/group/msg.json | 31 ----- standalone-network/group/msg_fungible.json | 37 ------ standalone-network/group/policy.json | 8 -- standalone-network/group/proposal.json | 112 ----------------- .../group/proposal_add-observer.json | 14 --- standalone-network/group/proposal_group.json | 12 -- .../group/proposal_group_examples.json | 23 ---- standalone-network/group/proposal_keygen.json | 12 -- standalone-network/init-multinode.sh | 86 ------------- standalone-network/init.sh | 43 ------- standalone-network/observers-complete.json | 40 ------ standalone-network/observers.json | 14 --- standalone-network/os_info/os1.json | 5 - standalone-network/os_info/os2.json | 5 - standalone-network/proposal.json | 29 ----- standalone-network/proposal_feemarket.json | 15 --- standalone-network/run-zetaclient.sh | 2 - standalone-network/run.sh | 39 ------ .../update_core_params/new_params.json | 11 -- .../update_core_params/update-params.sh | 2 - .../update_voting_period/proposal.json | 27 ---- .../update_voting_period.sh | 17 --- .../upgrade-integration-client.sh | 117 ----------------- .../upgrade-integration-download.sh | 67 ---------- standalone-network/upgrade-integration.sh | 119 ------------------ 47 files changed, 1554 deletions(-) delete mode 100644 standalone-network/add-emissions.sh delete mode 100644 standalone-network/add-observer.sh delete mode 100644 standalone-network/authz/commands.sh delete mode 100644 standalone-network/authz/tx.json delete mode 100755 standalone-network/cctx/cctx-creator-gas.sh delete mode 100755 standalone-network/cctx/cctx-creator-goerili.sh delete mode 100755 standalone-network/cctx/cctx-creator-zeta.sh delete mode 100644 standalone-network/cctx_authz/commands.sh delete mode 100644 standalone-network/cctx_authz/gas_price_voter_zeta.json delete mode 100644 standalone-network/cctx_authz/mario_inbound_vote.json delete mode 100644 standalone-network/cctx_authz/mario_outbound_vote.json delete mode 100644 standalone-network/cctx_authz/nonce_voter_zeta.json delete mode 100644 standalone-network/cctx_authz/zeta_inbound_vote.json delete mode 100644 standalone-network/cctx_authz/zeta_outbound_vote.json delete mode 100644 standalone-network/change-observer-params.sh delete mode 100644 standalone-network/evm-init delete mode 100644 standalone-network/gov/gov.sh delete mode 100644 standalone-network/gov/gov_observer_params_supported_chains.json delete mode 100644 standalone-network/group/add-observer.json delete mode 100644 standalone-network/group/group.sh delete mode 100644 standalone-network/group/members-updated.json delete mode 100644 standalone-network/group/members.json delete mode 100644 standalone-network/group/msg.json delete mode 100644 standalone-network/group/msg_fungible.json delete mode 100644 standalone-network/group/policy.json delete mode 100644 standalone-network/group/proposal.json delete mode 100644 standalone-network/group/proposal_add-observer.json delete mode 100644 standalone-network/group/proposal_group.json delete mode 100644 standalone-network/group/proposal_group_examples.json delete mode 100644 standalone-network/group/proposal_keygen.json delete mode 100755 standalone-network/init-multinode.sh delete mode 100755 standalone-network/init.sh delete mode 100644 standalone-network/observers-complete.json delete mode 100644 standalone-network/observers.json delete mode 100644 standalone-network/os_info/os1.json delete mode 100644 standalone-network/os_info/os2.json delete mode 100644 standalone-network/proposal.json delete mode 100644 standalone-network/proposal_feemarket.json delete mode 100644 standalone-network/run-zetaclient.sh delete mode 100755 standalone-network/run.sh delete mode 100644 standalone-network/update_core_params/new_params.json delete mode 100755 standalone-network/update_core_params/update-params.sh delete mode 100644 standalone-network/update_voting_period/proposal.json delete mode 100644 standalone-network/update_voting_period/update_voting_period.sh delete mode 100755 standalone-network/upgrade-integration-client.sh delete mode 100755 standalone-network/upgrade-integration-download.sh delete mode 100755 standalone-network/upgrade-integration.sh diff --git a/standalone-network/add-emissions.sh b/standalone-network/add-emissions.sh deleted file mode 100644 index 610e10e257..0000000000 --- a/standalone-network/add-emissions.sh +++ /dev/null @@ -1,23 +0,0 @@ -zetacored tx bank send zeta1syavy2npfyt9tcncdtsdzf7kny9lh777heefxk zeta1w43fn2ze2wyhu5hfmegr6vp52c3dgn0srdgymy 100000000000azeta --keyring-backend=test --chain-id=localnet_101-1 --fees=200000azeta --yes - -#total left in reserves -zetacored q bank balances zeta1w43fn2ze2wyhu5hfmegr6vp52c3dgn0srdgymy -#observer undistributed -zetacored q bank balances zeta1pyks89mqljlpgzenwa0g8zch0hptk6usd9vcuh -#tss undistributed -zetacored q bank balances zeta1v8v7zkyt7j3dc526k4alsu8vspvqqg342t27vu - - -#Zeta rewards self Delegation -zetacored q distribution rewards zeta1syavy2npfyt9tcncdtsdzf7kny9lh777heefxk zetavaloper1syavy2npfyt9tcncdtsdzf7kny9lh777nep4tq - - -#Mario delegate -zetacored tx staking delegate zetavaloper1syavy2npfyt9tcncdtsdzf7kny9lh777nep4tq 1000000000000000000000000azeta --from=mario --keyring-backend=test --chain-id=localnet_101-1 --fees=200000azeta -zetacored q distribution rewards zeta1l7hypmqk2yc334vc6vmdwzp5sdefygj2w5yj50 zetavaloper1syavy2npfyt9tcncdtsdzf7kny9lh777nep4tq - -#Zeta outstanding rewards (Total) -zetacored q distribution validator-outstanding-rewards zetavaloper1syavy2npfyt9tcncdtsdzf7kny9lh777nep4tq - -#Zeta commission rewards -zetacored q distribution commission zetavaloper1syavy2npfyt9tcncdtsdzf7kny9lh777nep4tq diff --git a/standalone-network/add-observer.sh b/standalone-network/add-observer.sh deleted file mode 100644 index 38d4953435..0000000000 --- a/standalone-network/add-observer.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -zetacored tx observer add-observer 5 InBoundTx --from zeta --fees=40azeta --chain-id=localnet_101-1 --keyring-backend=test -y --broadcast-mode=block -zetacored tx observer add-observer 5 OutBoundTx --from zeta --fees=40azeta --chain-id=localnet_101-1 --keyring-backend=test -y --broadcast-mode=block -zetacored q observer list-observer - -zetacored tx staking unbond zetavaloper1syavy2npfyt9tcncdtsdzf7kny9lh777nep4tq 99999900000000000000azeta --from zeta --gas=auto --gas-prices=0.0001azeta --gas-adjustment=1.5 --chain-id=localnet_101-1 --keyring-backend=test -y --broadcast-mode=block - - -#Add via genesis -#zetacored add-observer-list sample-observer-list.json -#zetacored add-observer Eth InBoundTx $(zetacored keys show zeta -a --keyring-backend=test) -#zetacored add-observer Eth OutBoundTx $(zetacored keys show zeta -a --keyring-backend=test) -#zetacored add-genesis-account $(zetacored keys show zetaeth -a --keyring-backend=test) 50000000000000000000000000000000azeta,500000000000000000000000000000000stake --keyring-backend=test - diff --git a/standalone-network/authz/commands.sh b/standalone-network/authz/commands.sh deleted file mode 100644 index f3083eb8e4..0000000000 --- a/standalone-network/authz/commands.sh +++ /dev/null @@ -1,10 +0,0 @@ -zetacored tx authz grant zeta1l7hypmqk2yc334vc6vmdwzp5sdefygj2w5yj50 delegate --allowed-validators zetavaloper1syavy2npfyt9tcncdtsdzf7kny9lh777nep4tq --from zeta --fees=40azeta --chain-id=localnet_101-1 --keyring-backend=test -y --broadcast-mode=block --spend-limit=100000000000azeta - -zetacored q authz grants zeta1syavy2npfyt9tcncdtsdzf7kny9lh777heefxk zeta1l7hypmqk2yc334vc6vmdwzp5sdefygj2w5yj50 -zetacored tx authz exec tx.json --from mario --gas=auto --gas-prices=0.1azeta --gas-adjustment=20 --chain-id=localnet_101-1 --keyring-backend=test -y --broadcast-mode=block -zetacored q staking delegations-to zetavaloper1syavy2npfyt9tcncdtsdzf7kny9lh777nep4tq - - - -zetacored tx authz grant zeta1l7hypmqk2yc334vc6vmdwzp5sdefygj2w5yj50 generic --from zeta --fees=40azeta --chain-id=localnet_101-1 --keyring-backend=test -y --broadcast-mode=block --msg-type=/zetachain.zetacore.crosschain.MsgGasPriceVoter - diff --git a/standalone-network/authz/tx.json b/standalone-network/authz/tx.json deleted file mode 100644 index 8e24e6c5bc..0000000000 --- a/standalone-network/authz/tx.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "body": { - "messages": [ - { - "@type": "/cosmos.staking.v1beta1.MsgDelegate", - "delegator_address": "zeta1syavy2npfyt9tcncdtsdzf7kny9lh777heefxk", - "validator_address": "zetavaloper1syavy2npfyt9tcncdtsdzf7kny9lh777nep4tq", - "amount": { - "denom": "azeta", - "amount": "100000000000" - } - } - ], - "memo": "", - "timeout_height": "0", - "extension_options": [], - "non_critical_extension_options": [] - }, - "auth_info": { - "signer_infos": [], - "fee": { - "amount": [ - { - "denom": "azeta", - "amount": "40" - } - ], - "gas_limit": "200000", - "payer": "", - "granter": "" - }, - "tip": null - }, - "signatures": [] -} diff --git a/standalone-network/cctx/cctx-creator-gas.sh b/standalone-network/cctx/cctx-creator-gas.sh deleted file mode 100755 index e17a327f7e..0000000000 --- a/standalone-network/cctx/cctx-creator-gas.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash -set -x - -zetacored tx observer add-observer 5 InBoundTx --from zeta --fees=40azeta --chain-id=localnet_101-1 --keyring-backend=test -y --broadcast-mode=block -#zetacored tx observer add-observer 5 OutBoundTx --from zeta --fees=40azeta --chain-id=localnet_101-1 --keyring-backend=test -y --broadcast-mode=block -zetacored tx observer add-observer 2374 InBoundTx --from zeta --fees=40azeta --chain-id=localnet_101-1 --keyring-backend=test -y --broadcast-mode=block -zetacored tx observer add-observer 2374 OutBoundTx --from zeta --fees=40azeta --chain-id=localnet_101-1 --keyring-backend=test -y --broadcast-mode=block -zetacored tx crosschain gas-price-voter 2374 10000000000 100 100 --from=zeta --keyring-backend=test --yes --chain-id=localnet_101-1 --broadcast-mode=block --gas=auto --gas-adjustment=2 --gas-prices=0.1azeta -zetacored tx crosschain nonce-voter Goerli 2374 --from=zeta --keyring-backend=test --yes --chain-id=localnet_101-1 --broadcast-mode=block --gas=auto --gas-adjustment=2 --gas-prices=0.1azeta --broadcast-mode=block - -zetacored tx crosschain inbound-voter 0x96B05C238b99768F349135de0653b687f9c13fEE 5 0x3b9Fe88DE29efD13240829A0c18E9EC7A44C3CA7 2374 10000000000000000000 0 "" "0x19398991572a825894b34b904ac1e3692720895351466b5c9e6bb7ae1e21d680" 100 Gas --from=zeta --keyring-backend=test --yes --chain-id=localnet_101-1 --broadcast-mode=block --gas=auto --gas-adjustment=2 --gas-prices=0.1azeta -zetacored q crosschain list-cctx -exit 0 -zetacored tx crosschain outbound-voter 0x752139735699b0ffa87571bf519867ab2aaf355733316842f9941e0efe5d05c9 hashout 1 7997428181981842964 0 2374 1 1 --from=zeta --keyring-backend=test --yes --chain-id=localnet_101-1 --broadcast-mode=block --gas=auto --gas-adjustment=2 --gas-prices=0.1azeta - -#zetacored tx crosschain zeta-conversion-rate-voter Goerli 1 1 --from=zeta --keyring-backend=test --yes --chain-id=localnet_101-1 --broadcast-mode=block --gas=auto --gas-adjustment=2 --gas-prices=0.1azeta diff --git a/standalone-network/cctx/cctx-creator-goerili.sh b/standalone-network/cctx/cctx-creator-goerili.sh deleted file mode 100755 index 71f0660d97..0000000000 --- a/standalone-network/cctx/cctx-creator-goerili.sh +++ /dev/null @@ -1,65 +0,0 @@ -set -x - - -zetacored tx crosschain gas-price-voter 1337 10000000000 100 100 --from=zeta --keyring-backend=test --yes --chain-id=localnet_101-1 --broadcast-mode=block --gas=auto --gas-adjustment=2 --gas-prices=0.1azeta -zetacored tx crosschain create-tss-voter tsspubkey 5 0 --from=zeta --keyring-backend=test --yes --chain-id=localnet_101-1 --broadcast-mode=block --gas=auto --gas-adjustment=2 --gas-prices=0.1azeta -zetacored tx crosschain gas-price-voter 1337 10000000000 100 100 --from=mario --keyring-backend=test --yes --chain-id=localnet_101-1 --broadcast-mode=block --gas=auto --gas-adjustment=2 --gas-prices=0.1azeta -zetacored tx crosschain create-tss-voter tsspubkey 5 0 --from=mario --keyring-backend=test --yes --chain-id=localnet_101-1 --broadcast-mode=block --gas=auto --gas-adjustment=2 --gas-prices=0.1azeta - -exit 0 -zetacored tx crosschain inbound-voter \ -0x96B05C238b99768F349135de0653b687f9c13fEE \ -1337 \ -0x3b9Fe88DE29efD13240829A0c18E9EC7A44C3CA7 \ -0x96B05C238b99768F349135de0653b687f9c13fEE \ -1337 \ -10000000000000000000 \ -"" \ -"0x19398991572a825894b34b904ac1e3692720895351466b5c9e6bb7ae1e21d680" \ -100 \ -Gas \ -"" \ ---from=zeta --keyring-backend=test --yes --chain-id=localnet_101-1 --broadcast-mode=block --gas=auto --gas-adjustment=2 --gas-prices=0.1azeta - - -zetacored tx crosschain inbound-voter \ -0x96B05C238b99768F349135de0653b687f9c13fEE \ -1337 \ -0x3b9Fe88DE29efD13240829A0c18E9EC7A44C3CA7 \ -0x96B05C238b99768F349135de0653b687f9c13fEE \ -1337 \ -10000000000000000000 \ -"" \ -"0x19398991572a825894b34b904ac1e3692720895351466b5c9e6bb7ae1e21d680" \ -100 \ -Gas \ -"" \ ---from=mario --keyring-backend=test --yes --chain-id=localnet_101-1 --broadcast-mode=block --gas=auto --gas-adjustment=2 --gas-prices=0.1azeta --output=json - -zetacored q crosschain list-cctx - -zetacored tx crosschain outbound-voter \ -0xead687de84b3969b4c18480f197d2812e0acb83f851acc2830f70e94c85cef55 \ -hashout \ -1 \ -7994721005120625032 \ -0 \ -1337 \ -1 \ -Gas \ ---from=zeta --keyring-backend=test --yes --chain-id=localnet_101-1 --broadcast-mode=block --gas=auto --gas-adjustment=2 --gas-prices=0.1azeta - -zetacored tx crosschain outbound-voter \ -0xead687de84b3969b4c18480f197d2812e0acb83f851acc2830f70e94c85cef55 \ -hashout \ -1 \ -7994721005120625032 \ -0 \ -1337 \ -1 \ -Gas \ ---from=mario --keyring-backend=test --yes --chain-id=localnet_101-1 --broadcast-mode=block --gas=auto --gas-adjustment=2 --gas-prices=0.1azeta - - - - diff --git a/standalone-network/cctx/cctx-creator-zeta.sh b/standalone-network/cctx/cctx-creator-zeta.sh deleted file mode 100755 index 1184991bea..0000000000 --- a/standalone-network/cctx/cctx-creator-zeta.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash -set -x - -#zetacored tx observer add-observer 5 InBoundTx --from zeta --fees=40azeta --chain-id=localnet_101-1 --keyring-backend=test -y --broadcast-mode=block -#zetacored tx observer add-observer 5 OutBoundTx --from zeta --fees=40azeta --chain-id=localnet_101-1 --keyring-backend=test -y --broadcast-mode=block -zetacored tx observer add-observer 2374 InBoundTx --from zeta --fees=40azeta --chain-id=localnet_101-1 --keyring-backend=test -y --broadcast-mode=block -zetacored tx observer add-observer 2374 OutBoundTx --from zeta --fees=40azeta --chain-id=localnet_101-1 --keyring-backend=test -y --broadcast-mode=block -zetacored tx crosschain gas-price-voter 1 10000000000 100 100 --from=zeta --keyring-backend=test --yes --chain-id=localnet_101-1 --broadcast-mode=block --gas=auto --gas-adjustment=2 --gas-prices=0.1azeta -zetacored tx crosschain nonce-voter Goerli 2374 --from=zeta --keyring-backend=test --yes --chain-id=localnet_101-1 --broadcast-mode=block --gas=auto --gas-adjustment=2 --gas-prices=0.1azeta --broadcast-mode=block - -zetacored tx crosschain inbound-voter 0x96B05C238b99768F349135de0653b687f9c13fEE 5 0x3b9Fe88DE29efD13240829A0c18E9EC7A44C3CA7 2374 10000000000000000000 0 "" "0x19398991572a825894b34b904ac1e3692720895351466b5c9e6bb7ae1e21d680" 100 Zeta --from=zeta --keyring-backend=test --yes --chain-id=localnet_101-1 --broadcast-mode=block --gas=auto --gas-adjustment=2 --gas-prices=0.1azeta -zetacored q crosschain list-cctx -exit 0 -zetacored tx crosschain outbound-voter 0x752139735699b0ffa87571bf519867ab2aaf355733316842f9941e0efe5d05c9 hashout 1 7997428181981842964 0 2374 1 1 --from=zeta --keyring-backend=test --yes --chain-id=localnet_101-1 --broadcast-mode=block --gas=auto --gas-adjustment=2 --gas-prices=0.1azeta - -#zetacored tx crosschain zeta-conversion-rate-voter Goerli 1 1 --from=zeta --keyring-backend=test --yes --chain-id=localnet_101-1 --broadcast-mode=block --gas=auto --gas-adjustment=2 --gas-prices=0.1azeta diff --git a/standalone-network/cctx_authz/commands.sh b/standalone-network/cctx_authz/commands.sh deleted file mode 100644 index c7d12d9753..0000000000 --- a/standalone-network/cctx_authz/commands.sh +++ /dev/null @@ -1,31 +0,0 @@ - -#Grant executer authorization to execute the GAS PRICE VOTER, NONCE VOTER for validator `zeta` -zetacored tx authz grant zeta19wzjdtah4kl2vh77jks68cyy5gpjyurqltys99 generic --from zeta --fees=40azeta --chain-id=localnet_101-1 --keyring-backend=test -y --broadcast-mode=block --msg-type=/zetachain.zetacore.crosschain.MsgGasPriceVoter -zetacored tx authz grant zeta19wzjdtah4kl2vh77jks68cyy5gpjyurqltys99 generic --from zeta --fees=40azeta --chain-id=localnet_101-1 --keyring-backend=test -y --broadcast-mode=block --msg-type=/zetachain.zetacore.crosschain.MsgNonceVoter - -#Grant executer authorization to execute the Inbound and Outbound VOTER for observers `zeta` and `mario` -#These are essentially the list of transactions that the zetaclient does to process a CCTX end to end -zetacored tx authz grant zeta19wzjdtah4kl2vh77jks68cyy5gpjyurqltys99 generic --from zeta --fees=40azeta --chain-id=localnet_101-1 --keyring-backend=test -y --broadcast-mode=block --msg-type=/zetachain.zetacore.crosschain.MsgVoteOnObservedInboundTx -zetacored tx authz grant zeta19wzjdtah4kl2vh77jks68cyy5gpjyurqltys99 generic --from mario --fees=40azeta --chain-id=localnet_101-1 --keyring-backend=test -y --broadcast-mode=block --msg-type=/zetachain.zetacore.crosschain.MsgVoteOnObservedInboundTx - -zetacored tx authz grant zeta19wzjdtah4kl2vh77jks68cyy5gpjyurqltys99 generic --from zeta --fees=40azeta --chain-id=localnet_101-1 --keyring-backend=test -y --broadcast-mode=block --msg-type=/zetachain.zetacore.crosschain.MsgVoteOnObservedOutboundTx -zetacored tx authz grant zeta19wzjdtah4kl2vh77jks68cyy5gpjyurqltys99 generic --from mario --fees=40azeta --chain-id=localnet_101-1 --keyring-backend=test -y --broadcast-mode=block --msg-type=/zetachain.zetacore.crosschain.MsgVoteOnObservedOutboundTx - - -# Check all the grants -zetacored q authz grants zeta1syavy2npfyt9tcncdtsdzf7kny9lh777heefxk zeta19wzjdtah4kl2vh77jks68cyy5gpjyurqltys99 -zetacored q authz grants zeta1l7hypmqk2yc334vc6vmdwzp5sdefygj2w5yj50 zeta19wzjdtah4kl2vh77jks68cyy5gpjyurqltys99 - - -# Execute all messages from executer . At this time zeta and mario keys can be offline -zetacored tx authz exec gas_price_voter_zeta.json --from executer --gas=auto --gas-prices=0.1azeta --gas-adjustment=10 --chain-id=localnet_101-1 --keyring-backend=test -y --broadcast-mode=block -zetacored tx authz exec nonce_voter_zeta.json --from executer --gas=auto --gas-prices=0.1azeta --gas-adjustment=10 --chain-id=localnet_101-1 --keyring-backend=test -y --broadcast-mode=block -zetacored tx authz exec mario_inbound_vote.json --from executer --gas=auto --gas-prices=0.1azeta --gas-adjustment=10 --chain-id=localnet_101-1 --keyring-backend=test -y --broadcast-mode=block -zetacored tx authz exec zeta_inbound_vote.json --from executer --gas=auto --gas-prices=0.1azeta --gas-adjustment=10 --chain-id=localnet_101-1 --keyring-backend=test -y --broadcast-mode=block -zetacored tx authz exec zeta_outbound_vote.json --from executer --gas=auto --gas-prices=0.1azeta --gas-adjustment=10 --chain-id=localnet_101-1 --keyring-backend=test -y --broadcast-mode=block -zetacored tx authz exec mario_outbound_vote.json --from executer --gas=auto --gas-prices=0.1azeta --gas-adjustment=10 --chain-id=localnet_101-1 --keyring-backend=test -y --broadcast-mode=block - - - - - diff --git a/standalone-network/cctx_authz/gas_price_voter_zeta.json b/standalone-network/cctx_authz/gas_price_voter_zeta.json deleted file mode 100644 index 6f92a9fb89..0000000000 --- a/standalone-network/cctx_authz/gas_price_voter_zeta.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "body": { - "messages": [ - { - "@type": "/zetachain.zetacore.crosschain.MsgGasPriceVoter", - "creator": "zeta1syavy2npfyt9tcncdtsdzf7kny9lh777heefxk", - "chain_id": "1337", - "price": "10000000000", - "block_number": "100", - "supply": "100" - } - ], - "memo": "", - "timeout_height": "0", - "extension_options": [], - "non_critical_extension_options": [] - }, - "auth_info": { - "signer_infos": [], - "fee": { - "amount": [ - { - "denom": "azeta", - "amount": "5183" - } - ], - "gas_limit": "51828", - "payer": "", - "granter": "" - }, - "tip": null - }, - "signatures": [] -} diff --git a/standalone-network/cctx_authz/mario_inbound_vote.json b/standalone-network/cctx_authz/mario_inbound_vote.json deleted file mode 100644 index a54198cf19..0000000000 --- a/standalone-network/cctx_authz/mario_inbound_vote.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "body": { - "messages": [ - { - "@type": "/zetachain.zetacore.crosschain.MsgVoteOnObservedInboundTx", - "creator": "zeta1l7hypmqk2yc334vc6vmdwzp5sdefygj2w5yj50", - "sender": "0x96B05C238b99768F349135de0653b687f9c13fEE", - "sender_chain_id": "1337", - "receiver": "0x96B05C238b99768F349135de0653b687f9c13fEE", - "receiver_chain": "1337", - "amount": "10000000000000000000", - "message": "", - "in_tx_hash": "0x19398991572a825894b34b904ac1e3692720895351466b5c9e6bb7ae1e21d680", - "in_block_height": "100", - "gas_limit": "250000", - "coin_type": "Gas", - "tx_origin": "0x3b9Fe88DE29efD13240829A0c18E9EC7A44C3CA7", - "asset": "" - } - ], - "memo": "", - "timeout_height": "0", - "extension_options": [], - "non_critical_extension_options": [] - }, - "auth_info": { - "signer_infos": [], - "fee": { - "amount": [ - { - "denom": "azeta", - "amount": "16968" - } - ], - "gas_limit": "169672", - "payer": "", - "granter": "" - }, - "tip": null - }, - "signatures": [] -} diff --git a/standalone-network/cctx_authz/mario_outbound_vote.json b/standalone-network/cctx_authz/mario_outbound_vote.json deleted file mode 100644 index d2ff9a6696..0000000000 --- a/standalone-network/cctx_authz/mario_outbound_vote.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "body": { - "messages": [ - { - "@type": "/zetachain.zetacore.crosschain.MsgVoteOnObservedOutboundTx", - "creator": "zeta1l7hypmqk2yc334vc6vmdwzp5sdefygj2w5yj50", - "cctx_hash": "0xead687de84b3969b4c18480f197d2812e0acb83f851acc2830f70e94c85cef55", - "observed_outTx_hash": "hashout", - "observed_outTx_blockHeight": "1", - "zeta_minted": "7997428181981842964", - "status": "Success", - "outTx_chain": "1337", - "outTx_tss_nonce": "1", - "coin_type": "Gas" - } - ], - "memo": "", - "timeout_height": "0", - "extension_options": [], - "non_critical_extension_options": [] - }, - "auth_info": { - "signer_infos": [], - "fee": { - "amount": [ - { - "denom": "azeta", - "amount": "22450" - } - ], - "gas_limit": "224498", - "payer": "", - "granter": "" - }, - "tip": null - }, - "signatures": [] -} diff --git a/standalone-network/cctx_authz/nonce_voter_zeta.json b/standalone-network/cctx_authz/nonce_voter_zeta.json deleted file mode 100644 index ebf7884740..0000000000 --- a/standalone-network/cctx_authz/nonce_voter_zeta.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "body": { - "messages": [ - { - "@type": "/zetachain.zetacore.crosschain.MsgNonceVoter", - "creator": "zeta1syavy2npfyt9tcncdtsdzf7kny9lh777heefxk", - "chain_id": "1337", - "nonce": "1" - } - ], - "memo": "", - "timeout_height": "0", - "extension_options": [], - "non_critical_extension_options": [] - }, - "auth_info": { - "signer_infos": [], - "fee": { - "amount": [ - { - "denom": "azeta", - "amount": "13236" - } - ], - "gas_limit": "132360", - "payer": "", - "granter": "" - }, - "tip": null - }, - "signatures": [] -} diff --git a/standalone-network/cctx_authz/zeta_inbound_vote.json b/standalone-network/cctx_authz/zeta_inbound_vote.json deleted file mode 100644 index 69fb355b28..0000000000 --- a/standalone-network/cctx_authz/zeta_inbound_vote.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "body": { - "messages": [ - { - "@type": "/zetachain.zetacore.crosschain.MsgVoteOnObservedInboundTx", - "creator": "zeta1syavy2npfyt9tcncdtsdzf7kny9lh777heefxk", - "sender": "0x96B05C238b99768F349135de0653b687f9c13fEE", - "sender_chain_id": "1337", - "receiver": "0x96B05C238b99768F349135de0653b687f9c13fEE", - "receiver_chain": "1337", - "amount": "10000000000000000000", - "message": "", - "in_tx_hash": "0x19398991572a825894b34b904ac1e3692720895351466b5c9e6bb7ae1e21d680", - "in_block_height": "100", - "gas_limit": "250000", - "coin_type": "Gas", - "tx_origin": "0x3b9Fe88DE29efD13240829A0c18E9EC7A44C3CA7", - "asset": "" - } - ], - "memo": "", - "timeout_height": "0", - "extension_options": [], - "non_critical_extension_options": [] - }, - "auth_info": { - "signer_infos": [], - "fee": { - "amount": [ - { - "denom": "azeta", - "amount": "16948" - } - ], - "gas_limit": "169480", - "payer": "", - "granter": "" - }, - "tip": null - }, - "signatures": [] -} diff --git a/standalone-network/cctx_authz/zeta_outbound_vote.json b/standalone-network/cctx_authz/zeta_outbound_vote.json deleted file mode 100644 index d595d7506f..0000000000 --- a/standalone-network/cctx_authz/zeta_outbound_vote.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "body": { - "messages": [ - { - "@type": "/zetachain.zetacore.crosschain.MsgVoteOnObservedOutboundTx", - "creator": "zeta1syavy2npfyt9tcncdtsdzf7kny9lh777heefxk", - "cctx_hash": "0xead687de84b3969b4c18480f197d2812e0acb83f851acc2830f70e94c85cef55", - "observed_outTx_hash": "hashout", - "observed_outTx_blockHeight": "1", - "zeta_minted": "7997428181981842964", - "status": "Success", - "outTx_chain": "1337", - "outTx_tss_nonce": "1", - "coin_type": "Gas" - } - ], - "memo": "", - "timeout_height": "0", - "extension_options": [], - "non_critical_extension_options": [] - }, - "auth_info": { - "signer_infos": [], - "fee": { - "amount": [ - { - "denom": "azeta", - "amount": "22431" - } - ], - "gas_limit": "224306", - "payer": "", - "granter": "" - }, - "tip": null - }, - "signatures": [] -} diff --git a/standalone-network/change-observer-params.sh b/standalone-network/change-observer-params.sh deleted file mode 100644 index 4df238642f..0000000000 --- a/standalone-network/change-observer-params.sh +++ /dev/null @@ -1,2 +0,0 @@ -zetacored tx gov submit-proposal proposal_feemarket.json --from zeta --keyring-backend=test -b block --chain-id=localnet_101-1 --gas=auto --gas-prices=0.1azeta --gas-adjustment=1.5 --yes -zetacored tx gov vote 1 yes --from zeta --keyring-backend test --chain-id localnet_101-1 --yes --gas=auto --gas-prices=0.1azeta --gas-adjustment=1.5 \ No newline at end of file diff --git a/standalone-network/evm-init b/standalone-network/evm-init deleted file mode 100644 index 69980fbc09..0000000000 --- a/standalone-network/evm-init +++ /dev/null @@ -1,104 +0,0 @@ -#!/bin/bash - -set -x - -KEY1="alice" -KEY2="bob" -CHAINID="athens_8888-2" -MONIKER="localtestnet" -KEYRING="test" -KEYALGO="eth_secp256k1" -LOGLEVEL="info" -# to trace evm -TRACE="--trace" -#TRACE="" - -# validate dependencies are installed -command -v jq > /dev/null 2>&1 || { echo >&2 "jq not installed. More info: https://stedolan.github.io/jq/download/"; exit 1; } - -# remove existing daemon and client -rm -rf ~/.zetacored* - -make install - -zetacored config keyring-backend $KEYRING --home ~/.zetacored -zetacored config chain-id $CHAINID --home ~/.zetacored - -# if $KEY exists it should be deleted -#zetacored keys add $KEY1 --keyring-backend $KEYRING --algo $KEYALGO -echo "Generating deterministic account - alice" -echo "race draft rival universe maid cheese steel logic crowd fork comic easy truth drift tomorrow eye buddy head time cash swing swift midnight borrow" | zetacored keys add alice --recover --keyring-backend $KEYRING --algo=secp256k1 --home ~/.zetacored - -echo "Generating deterministic account - bob" -echo "hand inmate canvas head lunar naive increase recycle dog ecology inhale december wide bubble hockey dice worth gravity ketchup feed balance parent secret orchard" | zetacored keys add bob --recover --keyring-backend $KEYRING --home ~/.zetacored - - -# Set moniker and chain-id for Ethermint (Moniker can be anything, chain-id must be an integer) -zetacored init $MONIKER --chain-id $CHAINID --home ~/.zetacored - -# Change parameter token denominations to aphoton -cat $HOME/.zetacored/config/genesis.json | jq '.app_state["staking"]["params"]["bond_denom"]="azeta"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json -cat $HOME/.zetacored/config/genesis.json | jq '.app_state["crisis"]["constant_fee"]["denom"]="azeta"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json -cat $HOME/.zetacored/config/genesis.json | jq '.app_state["gov"]["deposit_params"]["min_deposit"][0]["denom"]="azeta"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json -cat $HOME/.zetacored/config/genesis.json | jq '.app_state["mint"]["params"]["mint_denom"]="azeta"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json -cat $HOME/.zetacored/config/genesis.json | jq '.app_state["evm"]["params"]["evm_denom"]="azeta"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json - - -# Set gas limit in genesis -cat $HOME/.zetacored/config/genesis.json | jq '.consensus_params["block"]["max_gas"]="100000000"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json - -# disable produce empty block -if [[ "$OSTYPE" == "darwin"* ]]; then - sed -i '' 's/create_empty_blocks = true/create_empty_blocks = false/g' $HOME/.zetacored/config/config.toml - else - sed -i 's/create_empty_blocks = true/create_empty_blocks = false/g' $HOME/.zetacored/config/config.toml -fi - -if [[ $1 == "pending" ]]; then - if [[ "$OSTYPE" == "darwin"* ]]; then - sed -i '' 's/create_empty_blocks_interval = "0s"/create_empty_blocks_interval = "30s"/g' $HOME/.zetacored/config/config.toml - sed -i '' 's/timeout_propose = "3s"/timeout_propose = "30s"/g' $HOME/.zetacored/config/config.toml - sed -i '' 's/timeout_propose_delta = "500ms"/timeout_propose_delta = "5s"/g' $HOME/.zetacored/config/config.toml - sed -i '' 's/timeout_prevote = "1s"/timeout_prevote = "10s"/g' $HOME/.zetacored/config/config.toml - sed -i '' 's/timeout_prevote_delta = "500ms"/timeout_prevote_delta = "5s"/g' $HOME/.zetacored/config/config.toml - sed -i '' 's/timeout_precommit = "1s"/timeout_precommit = "10s"/g' $HOME/.zetacored/config/config.toml - sed -i '' 's/timeout_precommit_delta = "500ms"/timeout_precommit_delta = "5s"/g' $HOME/.zetacored/config/config.toml - sed -i '' 's/timeout_commit = "5s"/timeout_commit = "150s"/g' $HOME/.zetacored/config/config.toml - sed -i '' 's/timeout_broadcast_tx_commit = "10s"/timeout_broadcast_tx_commit = "150s"/g' $HOME/.zetacored/config/config.toml - sed -i '/\[api\]/,+3 s/enable = false/enable = true/' ~/.zetacored/config/app.toml - - else - sed -i 's/create_empty_blocks_interval = "0s"/create_empty_blocks_interval = "30s"/g' $HOME/.zetacored/config/config.toml - sed -i 's/timeout_propose = "3s"/timeout_propose = "30s"/g' $HOME/.zetacored/config/config.toml - sed -i 's/timeout_propose_delta = "500ms"/timeout_propose_delta = "5s"/g' $HOME/.zetacored/config/config.toml - sed -i 's/timeout_prevote = "1s"/timeout_prevote = "10s"/g' $HOME/.zetacored/config/config.toml - sed -i 's/timeout_prevote_delta = "500ms"/timeout_prevote_delta = "5s"/g' $HOME/.zetacored/config/config.toml - sed -i 's/timeout_precommit = "1s"/timeout_precommit = "10s"/g' $HOME/.zetacored/config/config.toml - sed -i 's/timeout_precommit_delta = "500ms"/timeout_precommit_delta = "5s"/g' $HOME/.zetacored/config/config.toml - sed -i 's/timeout_commit = "5s"/timeout_commit = "150s"/g' $HOME/.zetacored/config/config.toml - sed -i 's/timeout_broadcast_tx_commit = "10s"/timeout_broadcast_tx_commit = "150s"/g' $HOME/.zetacored/config/config.toml - sed -i '/\[api\]/,+3 s/enable = false/enable = true/' ~/.zetacored/config/app.toml - - fi -fi - -# Allocate genesis accounts (cosmos formatted addresses) -zetacored add-genesis-account $KEY1 100000000000000000000000000azeta --keyring-backend $KEYRING --home ~/.zetacored -zetacored add-genesis-account $KEY2 1000000000000000000000azeta --keyring-backend $KEYRING --home ~/.zetacored - - -# Sign genesis transaction -zetacored gentx $KEY1 1000000000000000000000azeta --keyring-backend $KEYRING --chain-id $CHAINID --home ~/.zetacored - -# Collect genesis tx -zetacored collect-gentxs --home ~/.zetacored - -# Run this to ensure everything worked and that the genesis file is setup correctly -zetacored validate-genesis --home ~/.zetacored - -if [[ $1 == "pending" ]]; then - echo "pending mode is on, please wait for the first block committed." -fi - -# Start the node (remove the --pruning=nothing flag if historical queries are not needed) -zetacored start --pruning=nothing $TRACE --log_level $LOGLEVEL --minimum-gas-prices=0.0001azeta --json-rpc.api eth,txpool,personal,net,debug,web3,miner --api.enable --home ~/.zetacored diff --git a/standalone-network/gov/gov.sh b/standalone-network/gov/gov.sh deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/standalone-network/gov/gov_observer_params_supported_chains.json b/standalone-network/gov/gov_observer_params_supported_chains.json deleted file mode 100644 index 6fc8ca324b..0000000000 --- a/standalone-network/gov/gov_observer_params_supported_chains.json +++ /dev/null @@ -1,58 +0,0 @@ -{ - "title": "Observer Param Change", - "description": "Update observer params", - "changes": [ - { - "subspace": "observer", - "key": "ObserverParams", - "value": [ - { - "chain": { - "chain_name": 6, - "chain_id": 5 - }, - "ballot_threshold": "0.660000000000000000", - "min_observer_delegation": "10000000000.000000000000000000", - "is_supported": "true" - }, - { - "chain": { - "chain_name": 11, - "chain_id": 7001 - }, - "ballot_threshold": "0.660000000000000000", - "min_observer_delegation": "10000000000.000000000000000000", - "is_supported": "true" - }, - { - "chain": { - "chain_name": 10, - "chain_id": 97 - }, - "ballot_threshold": "0.660000000000000000", - "min_observer_delegation": "10000000000.000000000000000000", - "is_supported": "true" - }, - { - "chain": { - "chain_name": 12, - "chain_id": 18332 - }, - "ballot_threshold": "0.660000000000000000", - "min_observer_delegation": "10000000000.000000000000000000", - "is_supported": "true" - }, - { - "chain": { - "chain_name": 7, - "chain_id": 80001 - }, - "ballot_threshold": "0.660000000000000000", - "min_observer_delegation": "10000000000.000000000000000000", - "is_supported": "true" - } - ] - } - ], - "deposit": "10000000azeta" -} \ No newline at end of file diff --git a/standalone-network/group/add-observer.json b/standalone-network/group/add-observer.json deleted file mode 100644 index d3a0988d0c..0000000000 --- a/standalone-network/group/add-observer.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "body": { - "messages": [ - { - "@type": "/zetachain.zetacore.observer.MsgAddObserver", - "creator": "zeta13c7p3xrhd6q2rx3h235jpt8pjdwvacyw6twpax", - "observer_address": "zeta1cv5nqpay7p5r2y9apkl97zute45d5je3f06e4j", - "zetaclient_grantee_pubkey": "zetapub1addwnpepq0ss57s6hdheyfgyymyvllcd6rfyqn6jayyvkuff8mrlvrluuktrwvcjfve", - "add_node_account_only": true - } - ], - "memo": "", - "timeout_height": "0", - "extension_options": [], - "non_critical_extension_options": [] - }, - "auth_info": { - "signer_infos": [], - "fee": { - "amount": [], - "gas_limit": "200000", - "payer": "", - "granter": "" - }, - "tip": null - }, - "signatures": [] -} diff --git a/standalone-network/group/group.sh b/standalone-network/group/group.sh deleted file mode 100644 index 1e678f167e..0000000000 --- a/standalone-network/group/group.sh +++ /dev/null @@ -1,11 +0,0 @@ -zetacored tx group create-group-with-policy zeta13c7p3xrhd6q2rx3h235jpt8pjdwvacyw6twpax group-metadata group-policy-metadata members.json policy.json --from zeta --fees=40azeta --chain-id=localnet_101-1 --keyring-backend=test -y --broadcast-mode=block -zetacored tx group submit-proposal proposal_keygen.json --from zeta --fees=40azeta --chain-id=localnet_101-1 --keyring-backend=test -y --broadcast-mode=block --exec=1 -zetacored tx group vote 2 zeta13c7p3xrhd6q2rx3h235jpt8pjdwvacyw6twpax VOTE_OPTION_YES metadata --from zeta --fees=40azeta --chain-id=localnet_101-1 --keyring-backend=test -y --broadcast-mode=block -zetacored tx group vote 2 zeta1f203dypqg5jh9hqfx0gfkmmnkdfuat3jr45ep2 VOTE_OPTION_YES metadata --from mario --fees=40azeta --chain-id=localnet_101-1 --keyring-backend=test -y --broadcast-mode=block -zetacored q group proposal 2 -zetacored tx group exec 2 --from zeta --fees=40azeta --chain-id=localnet_101-1 --keyring-backend=test -y --broadcast-mode=block -zetacored q group group-policies-by-admin zeta13c7p3xrhd6q2rx3h235jpt8pjdwvacyw6twpax - - -#zetacored q group group-policy-info zeta1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsxn0x73 -#zetacored q group group-policies-by-group 1 \ No newline at end of file diff --git a/standalone-network/group/members-updated.json b/standalone-network/group/members-updated.json deleted file mode 100644 index 93473242f1..0000000000 --- a/standalone-network/group/members-updated.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "members": [ - { - "address": "zeta1syavy2npfyt9tcncdtsdzf7kny9lh777heefxk", - "weight": "1", - "metadata": "zetadmin" - }, - { - "address": "zeta1l7hypmqk2yc334vc6vmdwzp5sdefygj2w5yj50", - "weight": "0", - "metadata": "marioadmin" - } - ] -} diff --git a/standalone-network/group/members.json b/standalone-network/group/members.json deleted file mode 100644 index f536aaa959..0000000000 --- a/standalone-network/group/members.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "members": [ - { - "address": "zeta13c7p3xrhd6q2rx3h235jpt8pjdwvacyw6twpax", - "weight": "1", - "metadata": "zetadmin" - }, - { - "address": "zeta1f203dypqg5jh9hqfx0gfkmmnkdfuat3jr45ep2", - "weight": "1", - "metadata": "marioadmin" - } - ] -} diff --git a/standalone-network/group/msg.json b/standalone-network/group/msg.json deleted file mode 100644 index 1e1856a1c7..0000000000 --- a/standalone-network/group/msg.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "body": { - "messages": [ - { - "@type": "/zetachain.zetacore.crosschain.MsgUpdatePermissionFlags", - "creator": "zeta1syavy2npfyt9tcncdtsdzf7kny9lh777heefxk", - "isInboundEnabled": false - }, - ], - "memo": "", - "timeout_height": "0", - "extension_options": [], - "non_critical_extension_options": [] - }, - "auth_info": { - "signer_infos": [], - "fee": { - "amount": [ - { - "denom": "azeta", - "amount": "40" - } - ], - "gas_limit": "200000", - "payer": "", - "granter": "" - }, - "tip": null - }, - "signatures": [] -} diff --git a/standalone-network/group/msg_fungible.json b/standalone-network/group/msg_fungible.json deleted file mode 100644 index 43b84eec2c..0000000000 --- a/standalone-network/group/msg_fungible.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "body": { - "messages": [ - { - "@type": "/zetachain.zetacore.fungible.MsgDeployFungibleCoinZRC20", - "creator": "zeta1syavy2npfyt9tcncdtsdzf7kny9lh777heefxk", - "ERC20": "test", - "foreignChain": "test", - "decimals": 2, - "name": "test", - "symbol": "test", - "coinType": "Gas", - "gasLimit": "0" - } - ], - "memo": "", - "timeout_height": "0", - "extension_options": [], - "non_critical_extension_options": [] - }, - "auth_info": { - "signer_infos": [], - "fee": { - "amount": [ - { - "denom": "azeta", - "amount": "40" - } - ], - "gas_limit": "200000", - "payer": "", - "granter": "" - }, - "tip": null - }, - "signatures": [] -} diff --git a/standalone-network/group/policy.json b/standalone-network/group/policy.json deleted file mode 100644 index 7f21a03e09..0000000000 --- a/standalone-network/group/policy.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "@type": "/cosmos.group.v1.ThresholdDecisionPolicy", - "threshold": "1", - "windows": { - "voting_period": "20000s", - "min_execution_period": "0s" - } -} diff --git a/standalone-network/group/proposal.json b/standalone-network/group/proposal.json deleted file mode 100644 index e9b66b624e..0000000000 --- a/standalone-network/group/proposal.json +++ /dev/null @@ -1,112 +0,0 @@ -{ - "title": "Observer Param Change", - "description": "Change observer params", - "changes": [ - { - "subspace": "observer", - "key": "ObserverParams", - "value": [ - { - "chain": { - "chain_name": 12, - "chain_id": "18332" - }, - "ballot_threshold": "0.660000000000000000", - "min_observer_delegation": "10000000000.000000000000000000", - "is_supported": true - }, - { - "chain": { - "chain_name": 3, - "chain_id": "8332" - }, - "ballot_threshold": "0.660000000000000000", - "min_observer_delegation": "10000000000.000000000000000000", - "is_supported": true - }, - { - "chain": { - "chain_name": 4, - "chain_id": "137" - }, - "ballot_threshold": "0.660000000000000000", - "min_observer_delegation": "10000000000.000000000000000000", - "is_supported": true - }, - { - "chain": { - "chain_name": 7, - "chain_id": "80001" - }, - "ballot_threshold": "0.660000000000000000", - "min_observer_delegation": "10000000000.000000000000000000", - "is_supported": true - }, - { - "chain": { - "chain_name": 9, - "chain_id": "1001" - }, - "ballot_threshold": "0.660000000000000000", - "min_observer_delegation": "10000000000.000000000000000000", - "is_supported": true - }, - { - "chain": { - "chain_name": 10, - "chain_id": "97" - }, - "ballot_threshold": "0.660000000000000000", - "min_observer_delegation": "10000000000.000000000000000000", - "is_supported": true - }, - { - "chain": { - "chain_name": 5, - "chain_id": "56" - }, - "ballot_threshold": "0.660000000000000000", - "min_observer_delegation": "10000000000.000000000000000000", - "is_supported": true - }, - { - "chain": { - "chain_name": 1, - "chain_id": "1" - }, - "ballot_threshold": "0.660000000000000000", - "min_observer_delegation": "10000000000.000000000000000000", - "is_supported": true - }, - { - "chain": { - "chain_name": 6, - "chain_id": "5" - }, - "ballot_threshold": "0.660000000000000000", - "min_observer_delegation": "10000000000.000000000000000000", - "is_supported": true - }, - { - "chain": { - "chain_name": 14, - "chain_id": "1337" - }, - "ballot_threshold": "0.660000000000000000", - "min_observer_delegation": "10000000000.000000000000000000", - "is_supported": false - }, - { - "chain": { - "chain_name": 2, - "chain_id": "101" - }, - "ballot_threshold": "0.660000000000000000", - "min_observer_delegation": "10000000000.000000000000000000", - "is_supported": false - } - ] - } - ], - "deposit": "10000zeta" -} \ No newline at end of file diff --git a/standalone-network/group/proposal_add-observer.json b/standalone-network/group/proposal_add-observer.json deleted file mode 100644 index 996e168c2f..0000000000 --- a/standalone-network/group/proposal_add-observer.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "group_policy_address": "zeta1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsxn0x73", - "messages": [ - { - "@type": "/zetachain.zetacore.observer.MsgAddObserver", - "creator": "zeta1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsxn0x73", - "observer_address": "zeta1cv5nqpay7p5r2y9apkl97zute45d5je3f06e4j", - "zetaclient_grantee_pubkey": "zetapub1addwnpepq0ss57s6hdheyfgyymyvllcd6rfyqn6jayyvkuff8mrlvrluuktrwvcjfve", - "add_node_account_only": true - } - ], - "metadata": "", - "proposers": ["zeta13c7p3xrhd6q2rx3h235jpt8pjdwvacyw6twpax"] -} diff --git a/standalone-network/group/proposal_group.json b/standalone-network/group/proposal_group.json deleted file mode 100644 index 495f15cf0a..0000000000 --- a/standalone-network/group/proposal_group.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "group_policy_address": "zeta1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsxn0x73", - "messages": [ - { - "@type": "/zetachain.zetacore.crosschain.MsgUpdateKeygen", - "creator": "zeta1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsxn0x73", - "block": 100 - } - ], - "metadata": "", - "proposers": ["zeta13c7p3xrhd6q2rx3h235jpt8pjdwvacyw6twpax"] -} diff --git a/standalone-network/group/proposal_group_examples.json b/standalone-network/group/proposal_group_examples.json deleted file mode 100644 index a45bb3a9a2..0000000000 --- a/standalone-network/group/proposal_group_examples.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "group_policy_address": "zeta1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsxn0x73", - "messages": [ - { - "@type": "/zetachain.zetacore.crosschain.MsgUpdatePermissionFlags", - "creator": "zeta1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsxn0x73", - "isInboundEnabled": false - }, - { - "@type": "/zetachain.zetacore.fungible.MsgDeployFungibleCoinZRC20", - "creator": "zeta1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsxn0x73", - "ERC20": "test", - "foreignChain": "test", - "decimals": 2, - "name": "test", - "symbol": "test", - "coinType": "Gas", - "gasLimit": "0" - } - ], - "metadata": "", - "proposers": ["zeta13c7p3xrhd6q2rx3h235jpt8pjdwvacyw6twpax"] -} diff --git a/standalone-network/group/proposal_keygen.json b/standalone-network/group/proposal_keygen.json deleted file mode 100644 index a155bec515..0000000000 --- a/standalone-network/group/proposal_keygen.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "group_policy_address": "zeta1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsxn0x73", - "messages": [ - { - "@type": "/zetachain.zetacore.observer.MsgUpdateKeygen", - "creator": "zeta1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsxn0x73", - "block": 400 - } - ], - "metadata": "", - "proposers": ["zeta13c7p3xrhd6q2rx3h235jpt8pjdwvacyw6twpax"] -} diff --git a/standalone-network/init-multinode.sh b/standalone-network/init-multinode.sh deleted file mode 100755 index 0d66bc3dcf..0000000000 --- a/standalone-network/init-multinode.sh +++ /dev/null @@ -1,86 +0,0 @@ -#!/usr/bin/env bash - -### chain init script for development purposes only ### -rm -rf ~/.zetacored -kill -9 $(lsof -ti:26657) - -NODES="node0 node1 node2 node3" - -genesis_addresses=() -for NODE in $NODES; do - mkdir -p $HOME/.zetacored/$NODE - zetacored init test --chain-id=localnet_101-1 -o --home=$HOME/.zetacored/$NODE - zetacored keys add zeta --algo secp256k1 --keyring-backend=test --home=$HOME/.zetacored/$NODE - zetacored keys add mario --algo secp256k1 --keyring-backend=test --home=$HOME/.zetacored/$NODE - genesis_addresses+=$(zetacored keys show zeta -a --keyring-backend=test --home=$HOME/.zetacored/$NODE) - genesis_addresses+=" " - genesis_addresses+=$(zetacored keys show mario -a --keyring-backend=test --home=$HOME/.zetacored/$NODE) - genesis_addresses+=" " -done - -for address in $genesis_addresses; do - zetacored add-genesis-account $address 500000000000000000000000000000000azeta --keyring-backend=test --home=$HOME/.zetacored/node0 -done - -zetacored gentx zeta 10000000000000000azeta --chain-id=localnet_101-1 --keyring-backend=test --home=$HOME/.zetacored/node0 -for NODE in $NODES; do - if [ $NODE != "node0" ] - then - rm -rf $HOME/.zetacored/$NODE/config/genesis.json - cp $HOME/.zetacored/node0/config/genesis.json $HOME/.zetacored/$NODE/config/ - zetacored gentx zeta 10000000000000000azeta --chain-id=localnet_101-1 --keyring-backend=test --home=$HOME/.zetacored/$NODE - cp $HOME/.zetacored/$NODE/config/gentx/*.json $HOME/.zetacored/node0/config/gentx/ - fi -done - - -cat $HOME/.zetacored/node0/config/genesis.json | jq '.app_state["staking"]["params"]["bond_denom"]="azeta"' > $HOME/.zetacored/node0/config/tmp_genesis.json && mv $HOME/.zetacored/node0/config/tmp_genesis.json $HOME/.zetacored/node0/config/genesis.json -cat $HOME/.zetacored/node0/config/genesis.json | jq '.app_state["crisis"]["constant_fee"]["denom"]="azeta"' > $HOME/.zetacored/node0/config/tmp_genesis.json && mv $HOME/.zetacored/node0/config/tmp_genesis.json $HOME/.zetacored/node0/config/genesis.json -cat $HOME/.zetacored/node0/config/genesis.json | jq '.app_state["gov"]["deposit_params"]["min_deposit"][0]["denom"]="azeta"' > $HOME/.zetacored/node0/config/tmp_genesis.json && mv $HOME/.zetacored/node0/config/tmp_genesis.json $HOME/.zetacored/node0/config/genesis.json -cat $HOME/.zetacored/node0/config/genesis.json | jq '.app_state["mint"]["params"]["mint_denom"]="azeta"' > $HOME/.zetacored/node0/config/tmp_genesis.json && mv $HOME/.zetacored/node0/config/tmp_genesis.json $HOME/.zetacored/node0/config/genesis.json -cat $HOME/.zetacored/node0/config/genesis.json | jq '.app_state["evm"]["params"]["evm_denom"]="azeta"' > $HOME/.zetacored/node0/config/tmp_genesis.json && mv $HOME/.zetacored/node0/config/tmp_genesis.json $HOME/.zetacored/node0/config/genesis.json -cat $HOME/.zetacored/node0/config/genesis.json | jq '.consensus_params["block"]["max_gas"]="10000000"' > $HOME/.zetacored/node0/config/tmp_genesis.json && mv $HOME/.zetacored/node0/config/tmp_genesis.json $HOME/.zetacored/node0/config/genesis.json - -zetacored collect-gentxs --home=$HOME/.zetacored/node0 -zetacored validate-genesis --home=$HOME/.zetacored/node0 -for NODE in $NODES; do - if [ $NODE != "node0" ] - then - rm -rf $HOME/.zetacored/$NODE/config/genesis.json - cp $HOME/.zetacored/node0/config/genesis.json $HOME/.zetacored/$NODE/config/ - fi -done - -killall zetacored - - -p2p=27655 -grpc=9085 -grpcweb=9093 -tcp=27659 -rpcladdr=2665 -jsonrpc=8545 -ws=9545 - -for NODE in $NODES; do - echo "Starting $NODE" - zetacored start \ - --minimum-gas-prices=0.0001azeta \ - --home $HOME/.zetacored/$NODE \ - --p2p.laddr 0.0.0.0:$p2p \ - --grpc.address 0.0.0.0:$grpc \ - --grpc-web.address 0.0.0.0:$grpcweb \ - --address tcp://0.0.0.0:$tcp \ - --json-rpc.address 0.0.0.0:$jsonrpc \ - --json-rpc.ws-address 0.0.0.0:$ws \ - --rpc.laddr tcp://127.0.0.1:$rpcladdr >> $HOME/.zetacored/$NODE/abci.log 2>&1 & - ((p2p=p2p+1)) - ((grpc=grpc+1)) - ((grpcweb=grpcweb+1)) - ((tcp=tcp+1)) - ((rpcladdr=rpcladdr+1)) - ((jsonrpc=jsonrpc+1)) - ((ws=ws+1)) -done - -# TODO ADD peers to config \ No newline at end of file diff --git a/standalone-network/init.sh b/standalone-network/init.sh deleted file mode 100755 index af98c18083..0000000000 --- a/standalone-network/init.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env bash - -CHAINID="localnet_101-1" -KEYRING="test" -export DAEMON_HOME=$HOME/.zetacored -export DAEMON_NAME=zetacored - -### chain init script for development purposes only ### -rm -rf ~/.zetacored -kill -9 $(lsof -ti:26657) -zetacored config keyring-backend $KEYRING --home ~/.zetacored -zetacored config chain-id $CHAINID --home ~/.zetacored -echo "race draft rival universe maid cheese steel logic crowd fork comic easy truth drift tomorrow eye buddy head time cash swing swift midnight borrow" | zetacored keys add zeta --algo=secp256k1 --recover --keyring-backend=$KEYRING -echo "hand inmate canvas head lunar naive increase recycle dog ecology inhale december wide bubble hockey dice worth gravity ketchup feed balance parent secret orchard" | zetacored keys add mario --algo secp256k1 --recover --keyring-backend=$KEYRING -echo "lounge supply patch festival retire duck foster decline theme horror decline poverty behind clever harsh layer primary syrup depart fantasy session fossil dismiss east" | zetacored keys add executer_zeta --recover --keyring-backend=$KEYRING --algo secp256k1 -echo "debris dumb among crew celery derive judge spoon road oyster dad panic adult song attack net pole merge mystery pig actual penalty neither peasant"| zetacored keys add executer_mario --algo=secp256k1 --recover --keyring-backend=$KEYRING - -zetacored init Zetanode-Localnet --chain-id=$CHAINID -#Set config to use azeta -cat $HOME/.zetacored/config/genesis.json | jq '.app_state["staking"]["params"]["bond_denom"]="azeta"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json -cat $HOME/.zetacored/config/genesis.json | jq '.app_state["crisis"]["constant_fee"]["denom"]="azeta"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json -cat $HOME/.zetacored/config/genesis.json | jq '.app_state["gov"]["deposit_params"]["min_deposit"][0]["denom"]="azeta"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json -cat $HOME/.zetacored/config/genesis.json | jq '.app_state["mint"]["params"]["mint_denom"]="azeta"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json -cat $HOME/.zetacored/config/genesis.json | jq '.app_state["evm"]["params"]["evm_denom"]="azeta"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json -cat $HOME/.zetacored/config/genesis.json | jq '.consensus_params["block"]["max_gas"]="10000000"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json -cat $HOME/.zetacored/config/genesis.json | jq '.app_state["observer"]["params"]["admin_policy"][1]["address"]="zeta13c7p3xrhd6q2rx3h235jpt8pjdwvacyw6twpax"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json -cat $HOME/.zetacored/config/genesis.json | jq '.app_state["observer"]["params"]["admin_policy"][0]["address"]="zeta13c7p3xrhd6q2rx3h235jpt8pjdwvacyw6twpax"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json -contents="$(jq '.app_state.gov.voting_params.voting_period = "10s"' $DAEMON_HOME/config/genesis.json)" && \ -echo "${contents}" > $DAEMON_HOME/config/genesis.json -sed -i '/\[api\]/,+3 s/enable = false/enable = true/' ~/.zetacored/config/app.toml - - -zetacored add-observer-list standalone-network/observers.json --keygen-block=5 -zetacored gentx zeta 1000000000000000000000azeta --chain-id=$CHAINID --keyring-backend=$KEYRING - - - -echo "Collecting genesis txs..." -zetacored collect-gentxs - -echo "Validating genesis file..." -zetacored validate-genesis - diff --git a/standalone-network/observers-complete.json b/standalone-network/observers-complete.json deleted file mode 100644 index b94d885193..0000000000 --- a/standalone-network/observers-complete.json +++ /dev/null @@ -1,40 +0,0 @@ -[ - { - "ObserverAddress": "zeta1syavy2npfyt9tcncdtsdzf7kny9lh777heefxk", - "ZetaClientGranteeAddress": "zeta19wzjdtah4kl2vh77jks68cyy5gpjyurqltys99", - "StakingGranteeAddress": "zeta19wzjdtah4kl2vh77jks68cyy5gpjyurqltys99", - "StakingMaxTokens": "100000000", - "StakingValidatorAllowList": [ - "zetavaloper1syavy2npfyt9tcncdtsdzf7kny9lh777nep4tq" - ], - "SpendGranteeAddress": "zeta19wzjdtah4kl2vh77jks68cyy5gpjyurqltys99", - "SpendMaxTokens": "100000000", - "GovGranteeAddress": "zeta19wzjdtah4kl2vh77jks68cyy5gpjyurqltys99", - "NodeAccount": { - "creator": "zeta1syavy2npfyt9tcncdtsdzf7kny9lh777heefxk", - "tssSignerAddress": "zeta19wzjdtah4kl2vh77jks68cyy5gpjyurqltys99", - "pubkeySet": { - "secp256k1": "zetapub1addwnpepqggtjvkmj6apcqr6ynyc5edxf2mpf5fxp2d3kwupemxtfwvg6gm7qv79fw0" - } - } - }, - { - "ObserverAddress": "zeta1l7hypmqk2yc334vc6vmdwzp5sdefygj2w5yj50", - "ZetaClientGranteeAddress": "zeta19wzjdtah4kl2vh77jks68cyy5gpjyurqltys99", - "StakingGranteeAddress": "zeta19wzjdtah4kl2vh77jks68cyy5gpjyurqltys99", - "StakingMaxTokens": "100000000", - "StakingValidatorAllowList": [ - "zetavaloper1syavy2npfyt9tcncdtsdzf7kny9lh777nep4tq" - ], - "SpendGranteeAddress": "zeta19wzjdtah4kl2vh77jks68cyy5gpjyurqltys99", - "SpendMaxTokens": "100000000", - "GovGranteeAddress": "zeta19wzjdtah4kl2vh77jks68cyy5gpjyurqltys99", - "NodeAccount": { - "creator": "zeta1l7hypmqk2yc334vc6vmdwzp5sdefygj2w5yj50", - "tssSignerAddress": "zeta19wzjdtah4kl2vh77jks68cyy5gpjyurqltys99", - "pubkeySet": { - "secp256k1": "zetapub1addwnpepqggtjvkmj6apcqr6ynyc5edxf2mpf5fxp2d3kwupemxtfwvg6gm7qv79fw0" - } - } - } -] \ No newline at end of file diff --git a/standalone-network/observers.json b/standalone-network/observers.json deleted file mode 100644 index f39019ea02..0000000000 --- a/standalone-network/observers.json +++ /dev/null @@ -1,14 +0,0 @@ -[ - { - "IsObserver": "y", - "ObserverAddress": "zeta13c7p3xrhd6q2rx3h235jpt8pjdwvacyw6twpax", - "ZetaClientGranteeAddress": "zeta10up34mvwjhjd9xkq56fwsf0k75vtg287uav69n", - "ZetaClientGranteePubKey": "zetapub1addwnpepqtlu7fykuh875xjckz4mn4x0mzc25rrqk5qne7mrwxqmatgllv3nx6lrkdp" - }, - { - "IsObserver": "y", - "ObserverAddress": "zeta1f203dypqg5jh9hqfx0gfkmmnkdfuat3jr45ep2", - "ZetaClientGranteeAddress": "zeta1unzpyll3tmutf0r8sqpxpnj46vtdr59mw8qepx", - "ZetaClientGranteePubKey": "zetapub1addwnpepqwy5pmg39regpq0gkggxehmfm8hwmxxw94sch7qzh4smava0szs07kk5045" - } -] \ No newline at end of file diff --git a/standalone-network/os_info/os1.json b/standalone-network/os_info/os1.json deleted file mode 100644 index c613e61cc7..0000000000 --- a/standalone-network/os_info/os1.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "ObserverAddress": "zeta1n48d8es90mezvc33srhgedjjuk3t69zzp7v6d4", - "ZetaClientGranteeAddress": "zeta1cjrr268h72a8fpc3870r437r5e5e8aumlwvhe0", - "ZetaClientGranteePubKey": "zetapub1addwnpepqg2l4m4n5ywn470c4qwkj3fy632rdug0hmnygy97ha5t8pcgnq78zk9fke7" -} \ No newline at end of file diff --git a/standalone-network/os_info/os2.json b/standalone-network/os_info/os2.json deleted file mode 100644 index c613e61cc7..0000000000 --- a/standalone-network/os_info/os2.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "ObserverAddress": "zeta1n48d8es90mezvc33srhgedjjuk3t69zzp7v6d4", - "ZetaClientGranteeAddress": "zeta1cjrr268h72a8fpc3870r437r5e5e8aumlwvhe0", - "ZetaClientGranteePubKey": "zetapub1addwnpepqg2l4m4n5ywn470c4qwkj3fy632rdug0hmnygy97ha5t8pcgnq78zk9fke7" -} \ No newline at end of file diff --git a/standalone-network/proposal.json b/standalone-network/proposal.json deleted file mode 100644 index da505d13cb..0000000000 --- a/standalone-network/proposal.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "title": "Observer Param Change", - "description": "Update policy address", - "changes": [ - { - "subspace": "observer", - "key": "AdminParams", - "value": [ - { - "policy_type": 0, - "address": "zeta1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsxn0x73" - }, - { - "policy_type": 1, - "address": "zeta1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsxn0x73" - }, - { - "policy_type": 2, - "address": "zeta1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsxn0x73" - }, - { - "policy_type": 3, - "address": "zeta1afk9zr2hn2jsac63h4hm60vl9z3e5u69gndzf7c99cqge3vzwjzsxn0x73" - } - ] - } - ], - "deposit": "10000000azeta" -} \ No newline at end of file diff --git a/standalone-network/proposal_feemarket.json b/standalone-network/proposal_feemarket.json deleted file mode 100644 index 1ec114d19a..0000000000 --- a/standalone-network/proposal_feemarket.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "messages": [ - { - "@type": "/ethermint.feemarket.v1.MsgUpdateParams", - "authority": "zeta10d07y265gmmuvt4z0w9aw880jnsr700jvxasvr", - "params": { - "base_fee": "7", - "min_gas_price" : "100000000000000", - "base_fee_change_denominator": "8" - } - } - ], - "metadata" : "some metadata", - "deposit": "10000000azeta" -} \ No newline at end of file diff --git a/standalone-network/run-zetaclient.sh b/standalone-network/run-zetaclient.sh deleted file mode 100644 index 5ad3375ea9..0000000000 --- a/standalone-network/run-zetaclient.sh +++ /dev/null @@ -1,2 +0,0 @@ -zetaclientd init --chain-id localnet_101-1 --operator zeta13c7p3xrhd6q2rx3h235jpt8pjdwvacyw6twpax --hotkey=zeta --public-ip=0.0.0.0 -zetaclientd start \ No newline at end of file diff --git a/standalone-network/run.sh b/standalone-network/run.sh deleted file mode 100755 index 594478be42..0000000000 --- a/standalone-network/run.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env bash - -CHAINID="localnet_101-1" -KEYRING="test" -HOSTNAME=$(hostname) -signer="zeta" - - -killall zetacored -zetacored start --trace \ ---minimum-gas-prices=0.0001azeta \ ---json-rpc.api eth,txpool,personal,net,debug,web3,miner \ ---api.enable >> ~/.zetacored/zetacored.log 2>&1 & \ -#>> "$HOME"/.zetacored/zetanode.log 2>&1 & \ - -#--home ~/.zetacored \ -#--p2p.laddr 0.0.0.0:27655 \ -#--grpc.address 0.0.0.0:9096 \ -#--grpc-web.address 0.0.0.0:9093 \ -#--address tcp://0.0.0.0:27659 \ -#--rpc.laddr tcp://127.0.0.1:26657 \ -#--pruning custom \ -#--pruning-keep-recent 54000 \ -#--pruning-interval 10 \ -#--min-retain-blocks 54000 \ -#--state-sync.snapshot-interval 14400 \ -#--state-sync.snapshot-keep-recent 3 - -#echo "--> Submitting proposal to update admin policies " -#sleep 7 -#zetacored tx gov submit-legacy-proposal param-change standalone-network/proposal.json --from $signer --gas=auto --gas-adjustment=1.5 --gas-prices=0.001azeta --chain-id=$CHAINID --keyring-backend=$KEYRING -y --broadcast-mode=block -#echo "--> Submitting vote for proposal" -#sleep 7 -#zetacored tx gov vote 1 yes --from $signer --keyring-backend $KEYRING --chain-id $CHAINID --yes --fees=40azeta --broadcast-mode=block -sleep 7 -zetacored tx fungible deploy-system-contracts --from zeta --gas=auto --gas-prices=10000000000azeta --gas-adjustment=1.5 --chain-id=localnet_101-1 --keyring-backend=test -y --broadcast-mode=block - -tail -f ~/.zetacored/zetacored.log - diff --git a/standalone-network/update_core_params/new_params.json b/standalone-network/update_core_params/new_params.json deleted file mode 100644 index 2acc3a571e..0000000000 --- a/standalone-network/update_core_params/new_params.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "confirmation_count" : 10, - "gas_price_ticker" : 10, - "in_tx_ticker": 10, - "out_tx_ticker": 10, - "watch_utxo_ticker": 10, - "chain_id" : 101, - "zeta_token_contract_address" : "", - "connector_contract_address" : "", - "erc20_custody_contract_address" : "" -} \ No newline at end of file diff --git a/standalone-network/update_core_params/update-params.sh b/standalone-network/update_core_params/update-params.sh deleted file mode 100755 index 3cca5583aa..0000000000 --- a/standalone-network/update_core_params/update-params.sh +++ /dev/null @@ -1,2 +0,0 @@ -zetacored tx observer update-client-params 101 new_params.json --from zeta --fees=40azeta --chain-id=localnet_101-1 --keyring-backend=test -y --broadcast-mode=block -#zetacored tx observer update-client-params 101 new_params.json --from val_grantee_observer --fees=40azeta --chain-id=athens_101-1 --keyring-backend=test -y --broadcast-mode=block \ No newline at end of file diff --git a/standalone-network/update_voting_period/proposal.json b/standalone-network/update_voting_period/proposal.json deleted file mode 100644 index 34d1c709b6..0000000000 --- a/standalone-network/update_voting_period/proposal.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "title": "Gov Param Change", - "description": "Update voting period", - "changes": [ - { - "subspace": "gov", - "key": "votingparams", - "value": { - "voting_period": "86400" - } - }, - { - "subspace": "gov", - "key": "depositparams", - "value": { - "min_deposit": [ - { - "denom": "azeta", - "amount": "1000000" - } - ], - "max_deposit_period": "86400" - } - } - ], - "deposit": "1000000zeta" -} \ No newline at end of file diff --git a/standalone-network/update_voting_period/update_voting_period.sh b/standalone-network/update_voting_period/update_voting_period.sh deleted file mode 100644 index 417b0d3737..0000000000 --- a/standalone-network/update_voting_period/update_voting_period.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -CHAINID="atheens_7001-1" -KEYRING="test" -HOSTNAME=$(hostname) -signer="operator" -proposal_count=10 - -#PID=1 - -signerAddress=$(zetacored keys show $signer -a --keyring-backend=test) -echo "signerAddress: $signerAddress" -for (( i = 0; i < proposal_count; i++ )); do - zetacored tx gov submit-legacy-proposal param-change proposal.json --from $signer --gas=auto --gas-adjustment=1.5 --gas-prices=0.001azeta --chain-id=$CHAINID --keyring-backend=$KEYRING -y --broadcast-mode=block -done - - -#zetacored tx gov vote "$PID" yes --from $signer --keyring-backend $KEYRING --chain-id $CHAINID --yes --fees=40azeta --broadcast-mode=block \ No newline at end of file diff --git a/standalone-network/upgrade-integration-client.sh b/standalone-network/upgrade-integration-client.sh deleted file mode 100755 index e3bd6f73c0..0000000000 --- a/standalone-network/upgrade-integration-client.sh +++ /dev/null @@ -1,117 +0,0 @@ -#!/usr/bin/env bash - - -clibuilder() -{ - echo "" - echo "Usage: $0 -u UpgradeName -c CurrentBinary -n NewBinary" - echo -e "\t-u Name of the upgrade [Must match a handler defined in setup-handlers.go in NewBinary]" - echo -e "\t-c Branch name for old binary (Upgrade From)" - echo -e "\t-n Branch name for new binary (Upgrade To)" - exit 1 # Exit script after printing help -} - -while getopts "u:c:n:" opt -do - case "$opt" in - u ) UpgradeName="$OPTARG" ;; - c ) CurrentBinary="$OPTARG" ;; - n ) NewBinary="$OPTARG" ;; - ? ) clibuilder ;; # Print cliBuilder in case parameter is non-existent - esac -done - -if [ -z "$UpgradeName" ] || [ -z "$CurrentBinary" ] || [ -z "$NewBinary" ] -then - echo "Some or all of the parameters are empty"; - clibuilder -fi - - -export DAEMON_HOME=$HOME/.zetacore -export DAEMON_NAME=zetacored -export DAEMON_ALLOW_DOWNLOAD_BINARIES=true -export DAEMON_RESTART_AFTER_UPGRADE=true -export CLIENT_DAEMON_NAME=zetaclientd -export CLIENT_DAEMON_ARGS="-enable-chains,GOERLI,-val,zeta" - -make clean -rm -rf ~/.zetacore -rm -rf zetacore.log -rm -rf ZetaClient.log - -rm -rf $GOPATH/bin/zetacored -rm -rf $GOPATH/bin/old/zetacored -rm -rf $GOPATH/bin/new/zetacored - -# Setup old binary and start chain -mkdir -p $GOPATH/bin/old -mkdir -p $GOPATH/bin/new - -git checkout $CurrentBinary -make install -cp $GOPATH/bin/zetacored $GOPATH/bin/old/ -cp $GOPATH/bin/zetaclientd $GOPATH/bin/old/ -zetacored init test --chain-id=localnet -o - -echo "Generating deterministic account - zeta" -echo "race draft rival universe maid cheese steel logic crowd fork comic easy truth drift tomorrow eye buddy head time cash swing swift midnight borrow" | zetacored keys add zeta --recover --keyring-backend=test - -echo "Generating deterministic account - mario" -echo "hand inmate canvas head lunar naive increase recycle dog ecology inhale december wide bubble hockey dice worth gravity ketchup feed balance parent secret orchard" | zetacored keys add mario --recover --keyring-backend=test - - -zetacored add-genesis-account $(zetacored keys show zeta -a --keyring-backend=test) 500000000000000000000000000000000stake --keyring-backend=test -zetacored add-genesis-account $(zetacored keys show mario -a --keyring-backend=test) 500000000000000000000000000000000stake --keyring-backend=test - -zetacored gentx zeta 1000000000000000000000000stake --chain-id=localnet --keyring-backend=test - -echo "Collecting genesis txs..." -zetacored collect-gentxs - -echo "Validating genesis file..." -zetacored validate-genesis - - -mkdir -p $DAEMON_HOME/cosmovisor/genesis/bin -mkdir -p $DAEMON_HOME/cosmovisor/upgrades/$UpgradeName/bin - - -# Setup new binary -git checkout $NewBinary -rm -rf $GOPATH/bin/zetacored -rm -rf $GOPATH/bin/zetaclientd - -make install -cp $GOPATH/bin/zetacored $GOPATH/bin/new/ -cp $GOPATH/bin/zetaclientd $GOPATH/bin/new/ - - -# Setup cosmovisor -cp $GOPATH/bin/old/zetacored $DAEMON_HOME/cosmovisor/genesis/bin/ -cp $GOPATH/bin/new/zetacored $DAEMON_HOME/cosmovisor/upgrades/$UpgradeName/bin/ -cp $GOPATH/bin/old/zetaclientd $DAEMON_HOME/cosmovisor/genesis/bin/ -cp $GOPATH/bin/new/zetaclientd $DAEMON_HOME/cosmovisor/upgrades/$UpgradeName/bin/ - -chmod +x $DAEMON_HOME/cosmovisor/genesis/bin/zetacored -chmod +x $DAEMON_HOME/cosmovisor/genesis/bin/zetaclientd -chmod +x $DAEMON_HOME/cosmovisor/upgrades/$UpgradeName/bin/zetacored -chmod +x $DAEMON_HOME/cosmovisor/upgrades/$UpgradeName/bin/zetaclientd - -contents="$(jq '.app_state.gov.voting_params.voting_period = "10s"' $DAEMON_HOME/config/genesis.json)" && \ -echo "${contents}" > $DAEMON_HOME/config/genesis.json - -# Add state data here if required - -cosmovisor start --home ~/.zetacore/ --p2p.laddr 0.0.0.0:27655 --grpc.address 0.0.0.0:9096 --grpc-web.address 0.0.0.0:9093 --address tcp://0.0.0.0:27659 --rpc.laddr tcp://127.0.0.1:26657 >> zetanode.log 2>&1 & - -sleep 7 -zetacored tx gov submit-proposal software-upgrade $UpgradeName --from zeta --deposit 100000000stake --upgrade-height 10 --title $UpgradeName --description $UpgradeName --keyring-backend test --chain-id localnet --yes -sleep 7 -zetacored tx gov vote 1 yes --from zeta --keyring-backend test --chain-id localnet --yes -clear -sleep 7 -zetacored query gov proposal 1 - -tail -f zetanode.log - diff --git a/standalone-network/upgrade-integration-download.sh b/standalone-network/upgrade-integration-download.sh deleted file mode 100755 index bea2fb717e..0000000000 --- a/standalone-network/upgrade-integration-download.sh +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/env bash - -kill -9 $(lsof -ti:26657) -export DAEMON_HOME=$HOME/.zetacore -export DAEMON_NAME=zetacored -export DAEMON_ALLOW_DOWNLOAD_BINARIES=true -export DAEMON_RESTART_AFTER_UPGRADE=true -export CLIENT_DAEMON_NAME=zetaclientd -export CLIENT_DAEMON_ARGS="-enable-chains,GOERLI,-val,zeta" -export DAEMON_DATA_BACKUP_DIR=$DAEMON_HOME -export CLIENT_SKIP_UPGRADE=true -export CLIENT_START_PROCESS=true -export UNSAFE_SKIP_BACKUP=true - -rm -rf ~/.zetacore -rm -rf zetacore.log -rm -rf zetanode.log -rm -rf zetacore-debug.log -rm -rf GOERLI_debug.log -rm -rf ZetaClient.log - -make install -# Genesis -mkdir -p $DAEMON_HOME/cosmovisor/genesis/bin -#mkdir -p $DAEMON_HOME/cosmovisor/upgrades/0.2.1/bin -cp $GOPATH/bin/zetacored $DAEMON_HOME/cosmovisor/genesis/bin -cp $GOPATH/bin/zetaclientd $DAEMON_HOME/cosmovisor/genesis/bin - - -chmod +x $DAEMON_HOME/cosmovisor/genesis/bin/zetacored -chmod +x $DAEMON_HOME/cosmovisor/genesis/bin/zetaclientd - -zetacored init test --chain-id=localnet -o -echo "race draft rival universe maid cheese steel logic crowd fork comic easy truth drift tomorrow eye buddy head time cash swing swift midnight borrow" | zetacored keys add zeta --recover --keyring-backend=test -echo "hand inmate canvas head lunar naive increase recycle dog ecology inhale december wide bubble hockey dice worth gravity ketchup feed balance parent secret orchard" | zetacored keys add mario --recover --keyring-backend=test -zetacored add-genesis-account $(zetacored keys show zeta -a --keyring-backend=test) 500000000000000000000000000000000stake --keyring-backend=test -zetacored add-genesis-account $(zetacored keys show mario -a --keyring-backend=test) 500000000000000000000000000000000stake --keyring-backend=test -zetacored gentx zeta 1000000000000000000000000stake --chain-id=localnet --keyring-backend=test -zetacored collect-gentxs -zetacored validate-genesis - - -contents="$(jq '.app_state.gov.voting_params.voting_period = "10s"' $DAEMON_HOME/config/genesis.json)" && \ -echo "${contents}" > $DAEMON_HOME/config/genesis.json - - -cosmovisor start --home ~/.zetacore/ --p2p.laddr 0.0.0.0:27655 --grpc.address 0.0.0.0:9096 --grpc-web.address 0.0.0.0:9093 --address tcp://0.0.0.0:27659 --rpc.laddr tcp://127.0.0.1:26657 >> zetanode.log 2>&1 & - -sleep 7 -printf "Raising the governance proposal:\n" -zetacored tx gov submit-proposal software-upgrade 0.2.1 \ - --from zeta \ - --deposit 10000000000000000000stake \ - --upgrade-height 6 \ - --upgrade-info '{"binaries":{"zetaclientd-darwin/arm64":"https://filebin.net/4awhitgraq8eenpd/zetaclientd","zetacored-darwin/arm64":"https://filebin.net/4awhitgraq8eenpd/zetacored"}}' \ - --description "test-upgrade" \ - --title "test-upgrade" \ - --from zeta \ - --keyring-backend test \ - --chain-id localnet \ - --yes -sleep 7 -zetacored tx gov vote 1 yes --from zeta --keyring-backend test --chain-id localnet --yes -clear -sleep 10 -zetacored query gov proposal 1 -tail -f zetanode.log \ No newline at end of file diff --git a/standalone-network/upgrade-integration.sh b/standalone-network/upgrade-integration.sh deleted file mode 100755 index 9d421eeaec..0000000000 --- a/standalone-network/upgrade-integration.sh +++ /dev/null @@ -1,119 +0,0 @@ -clibuilder() -{ - echo "" - echo "Usage: $0 -u UpgradeName -c CurrentBinary -n NewBinary" - echo -e "\t-u Name of the upgrade [Must match a handler defined in setup-handlers.go in NewBinary]" - echo -e "\t-c Branch name for old binary (Upgrade From)" - echo -e "\t-n Branch name for new binary (Upgrade To)" - exit 1 # Exit script after printing help -} - -while getopts "u:c:n:" opt -do - case "$opt" in - u ) UpgradeName="$OPTARG" ;; - c ) CurrentBinary="$OPTARG" ;; - n ) NewBinary="$OPTARG" ;; - ? ) clibuilder ;; # Print cliBuilder in case parameter is non-existent - esac -done - -if [ -z "$UpgradeName" ] || [ -z "$CurrentBinary" ] || [ -z "$NewBinary" ] -then - echo "Some or all of the parameters are empty"; - clibuilder -fi - -KEYRING=test -CHAINID="localnet_101-1" -export DAEMON_HOME=$HOME/.zetacored -export DAEMON_NAME=zetacored -export DAEMON_ALLOW_DOWNLOAD_BINARIES=true -export DAEMON_RESTART_AFTER_UPGRADE=true -export CLIENT_DAEMON_NAME=zetaclientd -export CLIENT_DAEMON_ARGS="-enable-chains,GOERLI,-val,zeta" -export DAEMON_DATA_BACKUP_DIR=$DAEMON_HOME -export CLIENT_SKIP_UPGRADE=true -export CLIENT_START_PROCESS=false -export UNSAFE_SKIP_BACKUP=true - -make clean -rm -rf ~/.zetacore -rm -rf zetacore.log - -rm -rf $GOPATH/bin/zetacored -rm -rf $GOPATH/bin/old/zetacored -rm -rf $GOPATH/bin/new/zetacored - -# Setup old binary and start chain -mkdir -p $GOPATH/bin/old -mkdir -p $GOPATH/bin/new - -git checkout $CurrentBinary -git pull -make install-zetacore -cp $GOPATH/bin/zetacored $GOPATH/bin/old/ -zetacored init test --chain-id=localnet_101-1 -o -cat $HOME/.zetacored/config/genesis.json | jq '.app_state["staking"]["params"]["bond_denom"]="azeta"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json -cat $HOME/.zetacored/config/genesis.json | jq '.app_state["crisis"]["constant_fee"]["denom"]="azeta"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json -cat $HOME/.zetacored/config/genesis.json | jq '.app_state["gov"]["deposit_params"]["min_deposit"][0]["denom"]="azeta"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json -cat $HOME/.zetacored/config/genesis.json | jq '.app_state["mint"]["params"]["mint_denom"]="azeta"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json -cat $HOME/.zetacored/config/genesis.json | jq '.app_state["evm"]["params"]["evm_denom"]="azeta"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json -cat $HOME/.zetacored/config/genesis.json | jq '.consensus_params["block"]["max_gas"]="10000000"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json -echo "Generating deterministic account - zeta" -echo "race draft rival universe maid cheese steel logic crowd fork comic easy truth drift tomorrow eye buddy head time cash swing swift midnight borrow" | zetacored keys add zeta --algo secp256k1 --recover --keyring-backend=test -echo "Generating deterministic account - mario" -echo "hand inmate canvas head lunar naive increase recycle dog ecology inhale december wide bubble hockey dice worth gravity ketchup feed balance parent secret orchard" | zetacored keys add mario --algo secp256k1 --recover --keyring-backend=test - - - -zetacored add-observer-list standalone-network/observers.json --keygen-block=0 --tss-pubkey="tsspubkey" -zetacored gentx zeta 1000000000000000000000azeta --chain-id=$CHAINID --keyring-backend=$KEYRING - -echo "Collecting genesis txs..." -zetacored collect-gentxs - -echo "Validating genesis file..." -zetacored validate-genesis - - -mkdir -p $DAEMON_HOME/cosmovisor/genesis/bin -mkdir -p $DAEMON_HOME/cosmovisor/upgrades/$UpgradeName/bin - - -# Setup new binary -git checkout $NewBinary -git pull -rm -rf $GOPATH/bin/zetacored -make install -cp $GOPATH/bin/zetacored $GOPATH/bin/new/ - - -# Setup cosmovisor -# Genesis -cp $GOPATH/bin/old/zetacored $DAEMON_HOME/cosmovisor/genesis/bin -cp $GOPATH/bin/zetaclientd $DAEMON_HOME/cosmovisor/genesis/bin - -#Upgrades -cp $GOPATH/bin/new/zetacored $DAEMON_HOME/cosmovisor/upgrades/$UpgradeName/bin/ - -#Permissions -chmod +x $DAEMON_HOME/cosmovisor/genesis/bin/zetacored -chmod +x $DAEMON_HOME/cosmovisor/genesis/bin/zetaclientd -chmod +x $DAEMON_HOME/cosmovisor/upgrades/$UpgradeName/bin/zetacored - -contents="$(jq '.app_state.gov.voting_params.voting_period = "10s"' $DAEMON_HOME/config/genesis.json)" && \ -echo "${contents}" > $DAEMON_HOME/config/genesis.json - -# Add state data here if required - -cosmovisor start --home ~/.zetacored/ --p2p.laddr 0.0.0.0:27655 --grpc.address 0.0.0.0:9096 --grpc-web.address 0.0.0.0:9093 --address tcp://0.0.0.0:27659 --rpc.laddr tcp://127.0.0.1:26657 >> zetanode.log 2>&1 & -sleep 8 -zetacored tx gov submit-legacy-proposal software-upgrade $UpgradeName --from zeta --deposit 100000000azeta --upgrade-height 6 --title $UpgradeName --description $UpgradeName --keyring-backend test --chain-id localnet_101-1 --yes --no-validate --fees=200azeta --broadcast-mode block -sleep 8 -zetacored tx gov vote 1 yes --from zeta --keyring-backend test --chain-id localnet_101-1 --yes --fees=200azeta --broadcast-mode block -clear -sleep 7 -zetacored query gov proposal 1 - -tail -f zetanode.log From 481dcfed866f6845fe611b6ca3cec5cf59bc4eaf Mon Sep 17 00:00:00 2001 From: Tanmay Date: Fri, 2 Feb 2024 13:18:44 -0500 Subject: [PATCH 04/13] add changelog entry --- changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 4a9fcd1530..19c19d24d4 100644 --- a/changelog.md +++ b/changelog.md @@ -28,7 +28,7 @@ * [1585](https://github.com/zeta-chain/node/pull/1585) - Updated release instructions * [1615](https://github.com/zeta-chain/node/pull/1615) - Add upgrade handler for version v12.1.0 -* [1652](https://github.com/zeta-chain/node/pull/1652) - add admin to init script in standalone network +* [1694](https://github.com/zeta-chain/node/pull/1694) - remove standalone network ### Features From 74f148a9f87664a55fdbbd8a3ab5adf6029d6926 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Fri, 2 Feb 2024 13:55:16 -0500 Subject: [PATCH 05/13] use assert in x directory --- .../client/cli/cli_out_tx_tracker_test.go | 44 ++-- .../client/integrationtests/cli_helpers.go | 38 ++-- x/crosschain/genesis_test.go | 6 +- x/crosschain/keeper/abci_test.go | 22 +- x/crosschain/keeper/cctx_test.go | 18 +- x/crosschain/keeper/cctx_utils_test.go | 56 +++--- x/crosschain/keeper/evm_deposit_test.go | 48 ++--- .../keeper/finalized_inbounds_test.go | 18 +- x/crosschain/keeper/gas_payment_test.go | 88 ++++---- x/crosschain/keeper/grpc_query_cctx_test.go | 46 ++--- .../keeper/grpc_query_gas_price_test.go | 15 +- .../grpc_query_in_tx_hash_to_cctx_test.go | 38 ++-- .../grpc_query_last_block_height_test.go | 15 +- .../keeper/grpc_query_out_tx_tracker_test.go | 26 +-- .../keeper/in_tx_hash_to_cctx_test.go | 10 +- x/crosschain/keeper/in_tx_tracker_test.go | 36 ++-- x/crosschain/keeper/keeper_test.go | 4 +- .../msg_server_abort_stuck_cctx_test.go | 32 +-- .../msg_server_add_to_intx_tracker_test.go | 34 ++-- .../msg_server_add_to_outtx_tracker_test.go | 71 ++++--- .../msg_server_migrate_tss_funds_test.go | 48 ++--- .../keeper/msg_server_update_tss_test.go | 13 +- .../keeper/msg_server_vote_inbound_tx.go | 2 +- .../keeper/msg_server_vote_outbound_tx.go | 2 +- .../msg_server_vote_outbound_tx_test.go | 6 +- .../keeper/msg_server_whitelist_erc20_test.go | 36 ++-- x/crosschain/keeper/out_tx_tracker_test.go | 10 +- x/crosschain/keeper/utils_test.go | 44 ++-- x/crosschain/keeper/zeta_accounting_test.go | 18 +- x/crosschain/migrations/v4/migrate_test.go | 15 +- x/crosschain/types/cctx_utils_test.go | 26 +-- x/crosschain/types/genesis_test.go | 6 +- .../types/message_abort_stuck_cctx_test.go | 6 +- .../message_add_to_in_tx_tracker_test.go | 6 +- .../message_add_to_out_tx_tracker_test.go | 6 +- .../types/message_migrate_tss_funds_test.go | 6 +- .../types/message_update_tss_address_test.go | 6 +- ...essage_vote_on_observed_inbound_tx_test.go | 36 ++-- ...ssage_vote_on_observed_outbound_tx_test.go | 32 +-- x/emissions/genesis_test.go | 6 +- x/emissions/types/genesis_test.go | 6 +- .../client/cli/query_foreign_coins_test.go | 44 ++-- x/fungible/genesis_test.go | 6 +- x/fungible/keeper/deposits_test.go | 70 +++---- x/fungible/keeper/evm_hooks_test.go | 26 +-- x/fungible/keeper/evm_test.go | 188 +++++++++--------- x/fungible/keeper/foreign_coins_test.go | 26 +-- x/fungible/keeper/gas_coin_and_pool_test.go | 10 +- x/fungible/keeper/gas_price_test.go | 32 +-- x/fungible/keeper/gas_stability_pool_test.go | 32 +-- .../keeper/grpc_query_code_hash_test.go | 22 +- .../keeper/grpc_query_foreign_coins_test.go | 28 +-- x/fungible/keeper/grpc_query_params_test.go | 6 +- ..._server_deploy_fungible_coin_zrc20_test.go | 60 +++--- .../msg_server_deploy_system_contract_test.go | 12 +- .../msg_server_remove_foreign_coin_test.go | 16 +- ..._server_udpate_zrc20_liquidity_cap_test.go | 34 ++-- ...sg_server_update_contract_bytecode_test.go | 86 ++++---- .../msg_server_update_system_contract_test.go | 54 ++--- .../msg_server_update_zrc20_paused_status.go | 8 +- ..._server_update_zrc20_paused_status_test.go | 76 +++---- ...g_server_update_zrc20_withdraw_fee_test.go | 60 +++--- x/fungible/keeper/params_test.go | 4 +- x/fungible/keeper/system_contract_test.go | 60 +++--- x/fungible/keeper/zeta_test.go | 12 +- x/fungible/types/evm_test.go | 14 +- x/fungible/types/gas_stablity_pool_test.go | 6 +- x/fungible/types/genesis_test.go | 6 +- ...message_deploy_fungible_coin_zrc20_test.go | 6 +- .../message_deploy_system_contracts_test.go | 6 +- .../types/message_remove_foreign_coin_test.go | 6 +- .../message_update_contract_bytecode_test.go | 6 +- .../message_update_system_contract_test.go | 6 +- ...message_update_zrc20_liquidity_cap_test.go | 6 +- ...message_update_zrc20_paused_status_test.go | 6 +- .../message_update_zrc20_withdraw_fee_test.go | 6 +- x/observer/genesis_test.go | 6 +- x/observer/keeper/chain_nonces_test.go | 10 +- x/observer/keeper/chain_params_test.go | 26 +-- x/observer/keeper/grpc_query_blame_test.go | 30 +-- x/observer/keeper/grpc_query_keygen_test.go | 6 +- .../keeper/grpc_query_node_account_test.go | 15 +- x/observer/keeper/grpc_query_nonces_test.go | 15 +- x/observer/keeper/grpc_query_params_test.go | 6 +- x/observer/keeper/keeper_test.go | 4 +- .../msg_server_add_block_header_test.go | 31 ++- .../msg_server_remove_chain_params_test.go | 36 ++-- .../msg_server_update_chain_params_test.go | 50 ++--- ...msg_server_update_crosschain_flags_test.go | 98 ++++----- x/observer/keeper/nonce_to_cctx_test.go | 10 +- x/observer/keeper/params_test.go | 4 +- x/observer/keeper/pending_nonces_test.go | 20 +- x/observer/keeper/tss_test.go | 31 ++- x/observer/keeper/utils_test.go | 3 +- x/observer/migrations/v3/migrate_test.go | 18 +- x/observer/migrations/v5/migrate_test.go | 33 ++- x/observer/types/chain_params_test.go | 64 +++--- x/observer/types/genesis_test.go | 6 +- x/observer/types/message_add_observer_test.go | 6 +- x/observer/types/message_crosschain_flags.go | 4 +- .../types/message_crosschain_flags_test.go | 22 +- .../types/message_remove_chain_params_test.go | 6 +- .../message_set_ballot_threshold_test.go | 4 +- .../types/message_update_chain_params_test.go | 6 +- .../types/message_update_keygen_test.go | 6 +- .../types/message_update_observer_test.go | 6 +- 106 files changed, 1308 insertions(+), 1321 deletions(-) diff --git a/x/crosschain/client/cli/cli_out_tx_tracker_test.go b/x/crosschain/client/cli/cli_out_tx_tracker_test.go index 01976193dc..7346e573c5 100644 --- a/x/crosschain/client/cli/cli_out_tx_tracker_test.go +++ b/x/crosschain/client/cli/cli_out_tx_tracker_test.go @@ -4,7 +4,7 @@ import ( "fmt" "testing" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/app" "github.com/zeta-chain/zetacore/testutil/network" "github.com/zeta-chain/zetacore/testutil/nullify" @@ -15,7 +15,7 @@ func networkWithOutTxTrackerObjects(t *testing.T, n int) (*network.Network, []ty t.Helper() cfg := network.DefaultConfig() state := types.GenesisState{} - require.NoError(t, cfg.Codec.UnmarshalJSON(cfg.GenesisState[types.ModuleName], &state)) + assert.NoError(t, cfg.Codec.UnmarshalJSON(cfg.GenesisState[types.ModuleName], &state)) for i := 0; i < n; i++ { outTxTracker := types.OutTxTracker{ @@ -25,7 +25,7 @@ func networkWithOutTxTrackerObjects(t *testing.T, n int) (*network.Network, []ty state.OutTxTrackerList = append(state.OutTxTrackerList, outTxTracker) } buf, err := cfg.Codec.MarshalJSON(&state) - require.NoError(t, err) + assert.NoError(t, err) cfg.GenesisState[types.ModuleName] = buf //cfg.GenesisState = network.SetupZetaGenesisState(t, cfg.GenesisState, cfg.Codec) net, err := network.New(t, app.NodeDir, cfg) @@ -72,14 +72,14 @@ func networkWithOutTxTrackerObjects(t *testing.T, n int) (*network.Network, []ty // out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdShowOutTxTracker(), args) // if tc.err != nil { // stat, ok := status.FromError(tc.err) -// require.True(t, ok) -// require.ErrorIs(t, stat.Err(), tc.err) +// assert.True(t, ok) +// assert.ErrorIs(t, stat.Err(), tc.err) // } else { -// require.NoError(t, err) +// assert.NoError(t, err) // var resp types.QueryGetOutTxTrackerResponse -// require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) -// require.NotNil(t, resp.OutTxTracker) -// require.Equal(t, +// assert.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) +// assert.NotNil(t, resp.OutTxTracker) +// assert.Equal(t, // nullify.Fill(&tc.obj), // nullify.Fill(&resp.OutTxTracker), // ) @@ -112,11 +112,11 @@ func networkWithOutTxTrackerObjects(t *testing.T, n int) (*network.Network, []ty // for i := 0; i < len(objs); i += step { // args := request(nil, uint64(i), uint64(step), false) // out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdListOutTxTracker(), args) -// require.NoError(t, err) +// assert.NoError(t, err) // var resp types.QueryAllOutTxTrackerResponse -// require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) -// require.LessOrEqual(t, len(resp.OutTxTracker), step) -// require.Subset(t, +// assert.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) +// assert.LessOrEqual(t, len(resp.OutTxTracker), step) +// assert.Subset(t, // nullify.Fill(objs), // nullify.Fill(resp.OutTxTracker), // ) @@ -128,11 +128,11 @@ func networkWithOutTxTrackerObjects(t *testing.T, n int) (*network.Network, []ty // for i := 0; i < len(objs); i += step { // args := request(next, 0, uint64(step), false) // out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdListOutTxTracker(), args) -// require.NoError(t, err) +// assert.NoError(t, err) // var resp types.QueryAllOutTxTrackerResponse -// require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) -// require.LessOrEqual(t, len(resp.OutTxTracker), step) -// require.Subset(t, +// assert.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) +// assert.LessOrEqual(t, len(resp.OutTxTracker), step) +// assert.Subset(t, // nullify.Fill(objs), // nullify.Fill(resp.OutTxTracker), // ) @@ -142,12 +142,12 @@ func networkWithOutTxTrackerObjects(t *testing.T, n int) (*network.Network, []ty // t.Run("Total", func(t *testing.T) { // args := request(nil, 0, uint64(len(objs)), true) // out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdListOutTxTracker(), args) -// require.NoError(t, err) +// assert.NoError(t, err) // var resp types.QueryAllOutTxTrackerResponse -// require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) -// require.NoError(t, err) -// require.Equal(t, len(objs), int(resp.Pagination.Total)) -// require.ElementsMatch(t, +// assert.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) +// assert.NoError(t, err) +// assert.Equal(t, len(objs), int(resp.Pagination.Total)) +// assert.ElementsMatch(t, // nullify.Fill(objs), // nullify.Fill(resp.OutTxTracker), // ) diff --git a/x/crosschain/client/integrationtests/cli_helpers.go b/x/crosschain/client/integrationtests/cli_helpers.go index 3195782031..ec9465d48e 100644 --- a/x/crosschain/client/integrationtests/cli_helpers.go +++ b/x/crosschain/client/integrationtests/cli_helpers.go @@ -15,7 +15,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" authcli "github.com/cosmos/cosmos-sdk/x/auth/client/cli" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" tmcli "github.com/tendermint/tendermint/libs/cli" "github.com/zeta-chain/zetacore/common" "github.com/zeta-chain/zetacore/testutil/network" @@ -44,7 +44,7 @@ func WriteToNewTempFile(t testing.TB, s string) *os.File { fp := TempFile(t) _, err := fp.WriteString(s) - require.Nil(t, err) + assert.Nil(t, err) return fp } @@ -54,7 +54,7 @@ func TempFile(t testing.TB) *os.File { t.Helper() fp, err := os.CreateTemp(GetTempDir(t), "") - require.NoError(t, err) + assert.NoError(t, err) return fp } @@ -67,10 +67,10 @@ func GetTempDir(t testing.TB) string { // https://github.com/cosmos/cosmos-sdk/pull/10341 for // this change's rationale. tempdir, err := os.MkdirTemp("", "") - require.NoError(t, err) + assert.NoError(t, err) t.Cleanup(func() { err := os.RemoveAll(tempdir) - require.NoError(t, err) + assert.NoError(t, err) }) return tempdir } @@ -86,11 +86,11 @@ func BuildSignedDeploySystemContract(t testing.TB, val *network.Validator, denom fmt.Sprintf("--%s=%d", flags.FlagGas, 4000000), } out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, txArgs) - require.NoError(t, err) + assert.NoError(t, err) unsignerdTx := WriteToNewTempFile(t, out.String()) res, err := TxSignExec(val.ClientCtx, val.Address, unsignerdTx.Name(), "--offline", "--account-number", strconv.FormatUint(account.GetAccountNumber(), 10), "--sequence", strconv.FormatUint(account.GetSequence(), 10)) - require.NoError(t, err) + assert.NoError(t, err) return WriteToNewTempFile(t, res.String()) } @@ -112,11 +112,11 @@ func BuildSignedUpdateSystemContract( } args := append([]string{systemContractAddress}, txArgs...) out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args) - require.NoError(t, err) + assert.NoError(t, err) unsignerdTx := WriteToNewTempFile(t, out.String()) res, err := TxSignExec(val.ClientCtx, val.Address, unsignerdTx.Name(), "--offline", "--account-number", strconv.FormatUint(account.GetAccountNumber(), 10), "--sequence", strconv.FormatUint(account.GetSequence(), 10)) - require.NoError(t, err) + assert.NoError(t, err) return WriteToNewTempFile(t, res.String()) } @@ -145,11 +145,11 @@ func BuildSignedDeployETHZRC20( "1000000", }, txArgs...) out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args) - require.NoError(t, err) + assert.NoError(t, err) unsignerdTx := WriteToNewTempFile(t, out.String()) res, err := TxSignExec(val.ClientCtx, val.Address, unsignerdTx.Name(), "--offline", "--account-number", strconv.FormatUint(account.GetAccountNumber(), 10), "--sequence", strconv.FormatUint(account.GetSequence(), 10)) - require.NoError(t, err) + assert.NoError(t, err) return WriteToNewTempFile(t, res.String()) } @@ -171,11 +171,11 @@ func BuildSignedGasPriceVote(t testing.TB, val *network.Validator, denom string, } args := append(inboundVoterArgs, txArgs...) out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args) - require.NoError(t, err) + assert.NoError(t, err) unsignerdTx := WriteToNewTempFile(t, out.String()) res, err := TxSignExec(val.ClientCtx, val.Address, unsignerdTx.Name(), "--offline", "--account-number", strconv.FormatUint(account.GetAccountNumber(), 10), "--sequence", strconv.FormatUint(account.GetSequence(), 10)) - require.NoError(t, err) + assert.NoError(t, err) return WriteToNewTempFile(t, res.String()) } @@ -196,11 +196,11 @@ func BuildSignedTssVote(t testing.TB, val *network.Validator, denom string, acco } args := append(inboundVoterArgs, txArgs...) out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args) - require.NoError(t, err) + assert.NoError(t, err) unsignerdTx := WriteToNewTempFile(t, out.String()) res, err := TxSignExec(val.ClientCtx, val.Address, unsignerdTx.Name(), "--offline", "--account-number", strconv.FormatUint(account.GetAccountNumber(), 10), "--sequence", strconv.FormatUint(account.GetSequence(), 10)) - require.NoError(t, err) + assert.NoError(t, err) return WriteToNewTempFile(t, res.String()) } @@ -239,12 +239,12 @@ func BuildSignedOutboundVote( } args := append(outboundVoterArgs, txArgs...) out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args) - require.NoError(t, err) + assert.NoError(t, err) unsignerdTx := WriteToNewTempFile(t, out.String()) res, err := TxSignExec(val.ClientCtx, val.Address, unsignerdTx.Name(), "--offline", "--account-number", strconv.FormatUint(account.GetAccountNumber(), 10), "--sequence", strconv.FormatUint(account.GetSequence(), 10)) - require.NoError(t, err) + assert.NoError(t, err) return WriteToNewTempFile(t, res.String()) } @@ -274,11 +274,11 @@ func BuildSignedInboundVote(t testing.TB, val *network.Validator, denom string, } args := append(inboundVoterArgs, txArgs...) out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args) - require.NoError(t, err) + assert.NoError(t, err) unsignerdTx := WriteToNewTempFile(t, out.String()) res, err := TxSignExec(val.ClientCtx, val.Address, unsignerdTx.Name(), "--offline", "--account-number", strconv.FormatUint(account.GetAccountNumber(), 10), "--sequence", strconv.FormatUint(account.GetSequence(), 10)) - require.NoError(t, err) + assert.NoError(t, err) return WriteToNewTempFile(t, res.String()) } diff --git a/x/crosschain/genesis_test.go b/x/crosschain/genesis_test.go index 3ce6a94875..052e075108 100644 --- a/x/crosschain/genesis_test.go +++ b/x/crosschain/genesis_test.go @@ -3,7 +3,7 @@ package crosschain_test import ( "testing" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/nullify" "github.com/zeta-chain/zetacore/testutil/sample" @@ -46,10 +46,10 @@ func TestGenesis(t *testing.T) { k, ctx, _, _ := keepertest.CrosschainKeeper(t) crosschain.InitGenesis(ctx, *k, genesisState) got := crosschain.ExportGenesis(ctx, *k) - require.NotNil(t, got) + assert.NotNil(t, got) // Compare genesis after init and export nullify.Fill(&genesisState) nullify.Fill(got) - require.Equal(t, genesisState, *got) + assert.Equal(t, genesisState, *got) } diff --git a/x/crosschain/keeper/abci_test.go b/x/crosschain/keeper/abci_test.go index 12263a3587..4b1a0bbe39 100644 --- a/x/crosschain/keeper/abci_test.go +++ b/x/crosschain/keeper/abci_test.go @@ -6,7 +6,7 @@ import ( "time" "cosmossdk.io/math" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" testkeeper "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/x/crosschain/types" observertypes "github.com/zeta-chain/zetacore/x/observer/types" @@ -268,8 +268,8 @@ func TestKeeper_CheckAndUpdateCctxGasPrice(t *testing.T) { // ensure median gas price is set medianGasPrice, isFound := k.GetMedianGasPriceInUint(ctx, chainID) - require.True(t, isFound) - require.True(t, medianGasPrice.Equal(math.NewUint(tc.medianGasPrice))) + assert.True(t, isFound) + assert.True(t, medianGasPrice.Equal(math.NewUint(tc.medianGasPrice))) } // set block timestamp @@ -285,23 +285,23 @@ func TestKeeper_CheckAndUpdateCctxGasPrice(t *testing.T) { gasPriceIncrease, feesPaid, err := k.CheckAndUpdateCctxGasPrice(ctx, tc.cctx, tc.flags) if tc.isError { - require.Error(t, err) + assert.Error(t, err) return } - require.NoError(t, err) + assert.NoError(t, err) // check values - require.True(t, gasPriceIncrease.Equal(tc.expectedGasPriceIncrease), "expected %s, got %s", tc.expectedGasPriceIncrease.String(), gasPriceIncrease.String()) - require.True(t, feesPaid.Equal(tc.expectedAdditionalFees), "expected %s, got %s", tc.expectedAdditionalFees.String(), feesPaid.String()) + assert.True(t, gasPriceIncrease.Equal(tc.expectedGasPriceIncrease), "expected %s, got %s", tc.expectedGasPriceIncrease.String(), gasPriceIncrease.String()) + assert.True(t, feesPaid.Equal(tc.expectedAdditionalFees), "expected %s, got %s", tc.expectedAdditionalFees.String(), feesPaid.String()) // check cctx if !tc.expectedGasPriceIncrease.IsZero() { cctx, found := k.GetCrossChainTx(ctx, tc.cctx.Index) - require.True(t, found) + assert.True(t, found) newGasPrice, err := cctx.GetCurrentOutTxParam().GetGasPrice() - require.NoError(t, err) - require.EqualValues(t, tc.expectedGasPriceIncrease.AddUint64(previousGasPrice).Uint64(), newGasPrice, "%d - %d", tc.expectedGasPriceIncrease.Uint64(), previousGasPrice) - require.EqualValues(t, tc.blockTimestamp.Unix(), cctx.CctxStatus.LastUpdateTimestamp) + assert.NoError(t, err) + assert.EqualValues(t, tc.expectedGasPriceIncrease.AddUint64(previousGasPrice).Uint64(), newGasPrice, "%d - %d", tc.expectedGasPriceIncrease.Uint64(), previousGasPrice) + assert.EqualValues(t, tc.blockTimestamp.Unix(), cctx.CctxStatus.LastUpdateTimestamp) } }) } diff --git a/x/crosschain/keeper/cctx_test.go b/x/crosschain/keeper/cctx_test.go index 13218eca13..764ce660d9 100644 --- a/x/crosschain/keeper/cctx_test.go +++ b/x/crosschain/keeper/cctx_test.go @@ -7,7 +7,7 @@ import ( "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/types/query" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/crosschain/keeper" @@ -15,8 +15,6 @@ import ( "google.golang.org/grpc/status" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" - "github.com/zeta-chain/zetacore/common" "github.com/zeta-chain/zetacore/x/crosschain/types" ) @@ -188,9 +186,9 @@ func TestSendQuerySingle(t *testing.T) { t.Run(tc.desc, func(t *testing.T) { response, err := keeper.Cctx(wctx, tc.request) if tc.err != nil { - require.ErrorIs(t, err, tc.err) + assert.ErrorIs(t, err, tc.err) } else { - require.Equal(t, tc.response, response) + assert.Equal(t, tc.response, response) } }) } @@ -216,7 +214,7 @@ func TestSendQueryPaginated(t *testing.T) { step := 2 for i := 0; i < len(msgs); i += step { resp, err := keeper.CctxAll(wctx, request(nil, uint64(i), uint64(step), false)) - require.NoError(t, err) + assert.NoError(t, err) for j := i; j < len(msgs) && j < i+step; j++ { assert.Equal(t, &msgs[j], resp.CrossChainTx[j-i]) } @@ -227,7 +225,7 @@ func TestSendQueryPaginated(t *testing.T) { var next []byte for i := 0; i < len(msgs); i += step { resp, err := keeper.CctxAll(wctx, request(next, 0, uint64(step), false)) - require.NoError(t, err) + assert.NoError(t, err) for j := i; j < len(msgs) && j < i+step; j++ { assert.Equal(t, &msgs[j], resp.CrossChainTx[j-i]) } @@ -236,11 +234,11 @@ func TestSendQueryPaginated(t *testing.T) { }) t.Run("Total", func(t *testing.T) { resp, err := keeper.CctxAll(wctx, request(nil, 0, 0, true)) - require.NoError(t, err) - require.Equal(t, len(msgs), int(resp.Pagination.Total)) + assert.NoError(t, err) + assert.Equal(t, len(msgs), int(resp.Pagination.Total)) }) t.Run("InvalidRequest", func(t *testing.T) { _, err := keeper.CctxAll(wctx, nil) - require.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) + assert.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) }) } diff --git a/x/crosschain/keeper/cctx_utils_test.go b/x/crosschain/keeper/cctx_utils_test.go index 2d122bce7a..27c1509ffb 100644 --- a/x/crosschain/keeper/cctx_utils_test.go +++ b/x/crosschain/keeper/cctx_utils_test.go @@ -6,7 +6,7 @@ import ( "cosmossdk.io/math" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/common" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -44,12 +44,12 @@ func TestKeeper_RefundAmountOnZetaChain(t *testing.T) { }}, math.NewUint(42), ) - require.NoError(t, err) + assert.NoError(t, err) // check amount deposited in balance balance, err := zk.FungibleKeeper.BalanceOfZRC4(ctx, zrc20Addr, sender) - require.NoError(t, err) - require.Equal(t, uint64(42), balance.Uint64()) + assert.NoError(t, err) + assert.Equal(t, uint64(42), balance.Uint64()) // can refund again err = k.RefundAmountOnZetaChain(ctx, types.CrossChainTx{ @@ -61,10 +61,10 @@ func TestKeeper_RefundAmountOnZetaChain(t *testing.T) { }}, math.NewUint(42), ) - require.NoError(t, err) + assert.NoError(t, err) balance, err = zk.FungibleKeeper.BalanceOfZRC4(ctx, zrc20Addr, sender) - require.NoError(t, err) - require.Equal(t, uint64(84), balance.Uint64()) + assert.NoError(t, err) + assert.Equal(t, uint64(84), balance.Uint64()) }) t.Run("should fail with invalid cctx", func(t *testing.T) { @@ -76,7 +76,7 @@ func TestKeeper_RefundAmountOnZetaChain(t *testing.T) { }}, math.NewUint(42), ) - require.ErrorContains(t, err, "unsupported coin type") + assert.ErrorContains(t, err, "unsupported coin type") err = k.RefundAmountOnZetaChain(ctx, types.CrossChainTx{ InboundTxParams: &types.InboundTxParams{ @@ -84,7 +84,7 @@ func TestKeeper_RefundAmountOnZetaChain(t *testing.T) { }}, math.NewUint(42), ) - require.ErrorContains(t, err, "unsupported coin type") + assert.ErrorContains(t, err, "unsupported coin type") err = k.RefundAmountOnZetaChain(ctx, types.CrossChainTx{ InboundTxParams: &types.InboundTxParams{ @@ -93,7 +93,7 @@ func TestKeeper_RefundAmountOnZetaChain(t *testing.T) { }}, math.NewUint(42), ) - require.ErrorContains(t, err, "only EVM chains are supported") + assert.ErrorContains(t, err, "only EVM chains are supported") err = k.RefundAmountOnZetaChain(ctx, types.CrossChainTx{ InboundTxParams: &types.InboundTxParams{ @@ -103,7 +103,7 @@ func TestKeeper_RefundAmountOnZetaChain(t *testing.T) { }}, math.NewUint(42), ) - require.ErrorContains(t, err, "invalid sender address") + assert.ErrorContains(t, err, "invalid sender address") err = k.RefundAmountOnZetaChain(ctx, types.CrossChainTx{ InboundTxParams: &types.InboundTxParams{ @@ -114,7 +114,7 @@ func TestKeeper_RefundAmountOnZetaChain(t *testing.T) { }, math.Uint{}, ) - require.ErrorContains(t, err, "no amount to refund") + assert.ErrorContains(t, err, "no amount to refund") err = k.RefundAmountOnZetaChain(ctx, types.CrossChainTx{ InboundTxParams: &types.InboundTxParams{ @@ -124,7 +124,7 @@ func TestKeeper_RefundAmountOnZetaChain(t *testing.T) { }}, math.ZeroUint(), ) - require.ErrorContains(t, err, "no amount to refund") + assert.ErrorContains(t, err, "no amount to refund") // the foreign coin has not been set err = k.RefundAmountOnZetaChain(ctx, types.CrossChainTx{ @@ -136,7 +136,7 @@ func TestKeeper_RefundAmountOnZetaChain(t *testing.T) { }}, math.NewUint(42), ) - require.ErrorContains(t, err, "zrc not found") + assert.ErrorContains(t, err, "zrc not found") }) } @@ -145,8 +145,8 @@ func TestGetRevertGasLimit(t *testing.T) { k, ctx, _, _ := keepertest.CrosschainKeeper(t) gasLimit, err := k.GetRevertGasLimit(ctx, types.CrossChainTx{}) - require.NoError(t, err) - require.Equal(t, uint64(0), gasLimit) + assert.NoError(t, err) + assert.Equal(t, uint64(0), gasLimit) }) t.Run("should return 0 if coin type is not gas or erc20", func(t *testing.T) { @@ -156,8 +156,8 @@ func TestGetRevertGasLimit(t *testing.T) { InboundTxParams: &types.InboundTxParams{ CoinType: common.CoinType_Zeta, }}) - require.NoError(t, err) - require.Equal(t, uint64(0), gasLimit) + assert.NoError(t, err) + assert.Equal(t, uint64(0), gasLimit) }) t.Run("should return the gas limit of the gas token", func(t *testing.T) { @@ -169,15 +169,15 @@ func TestGetRevertGasLimit(t *testing.T) { gas := setupGasCoin(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper, chainID, "foo", "FOO") _, err := zk.FungibleKeeper.UpdateZRC20GasLimit(ctx, gas, big.NewInt(42)) - require.NoError(t, err) + assert.NoError(t, err) gasLimit, err := k.GetRevertGasLimit(ctx, types.CrossChainTx{ InboundTxParams: &types.InboundTxParams{ CoinType: common.CoinType_Gas, SenderChainId: chainID, }}) - require.NoError(t, err) - require.Equal(t, uint64(42), gasLimit) + assert.NoError(t, err) + assert.Equal(t, uint64(42), gasLimit) }) t.Run("should return the gas limit of the associated asset", func(t *testing.T) { @@ -199,7 +199,7 @@ func TestGetRevertGasLimit(t *testing.T) { ) _, err := zk.FungibleKeeper.UpdateZRC20GasLimit(ctx, zrc20Addr, big.NewInt(42)) - require.NoError(t, err) + assert.NoError(t, err) gasLimit, err := k.GetRevertGasLimit(ctx, types.CrossChainTx{ InboundTxParams: &types.InboundTxParams{ @@ -207,8 +207,8 @@ func TestGetRevertGasLimit(t *testing.T) { SenderChainId: chainID, Asset: asset, }}) - require.NoError(t, err) - require.Equal(t, uint64(42), gasLimit) + assert.NoError(t, err) + assert.Equal(t, uint64(42), gasLimit) }) t.Run("should fail if no gas coin found", func(t *testing.T) { @@ -219,7 +219,7 @@ func TestGetRevertGasLimit(t *testing.T) { CoinType: common.CoinType_Gas, SenderChainId: 999999, }}) - require.ErrorIs(t, err, types.ErrForeignCoinNotFound) + assert.ErrorIs(t, err, types.ErrForeignCoinNotFound) }) t.Run("should fail if query gas limit for gas coin fails", func(t *testing.T) { @@ -240,7 +240,7 @@ func TestGetRevertGasLimit(t *testing.T) { CoinType: common.CoinType_Gas, SenderChainId: chainID, }}) - require.ErrorIs(t, err, fungibletypes.ErrContractCall) + assert.ErrorIs(t, err, fungibletypes.ErrContractCall) }) t.Run("should fail if no asset found", func(t *testing.T) { @@ -251,7 +251,7 @@ func TestGetRevertGasLimit(t *testing.T) { CoinType: common.CoinType_ERC20, SenderChainId: 999999, }}) - require.ErrorIs(t, err, types.ErrForeignCoinNotFound) + assert.ErrorIs(t, err, types.ErrForeignCoinNotFound) }) t.Run("should fail if query gas limit for asset fails", func(t *testing.T) { @@ -275,6 +275,6 @@ func TestGetRevertGasLimit(t *testing.T) { SenderChainId: chainID, Asset: asset, }}) - require.ErrorIs(t, err, fungibletypes.ErrContractCall) + assert.ErrorIs(t, err, fungibletypes.ErrContractCall) }) } diff --git a/x/crosschain/keeper/evm_deposit_test.go b/x/crosschain/keeper/evm_deposit_test.go index 65483d89c1..08287b7047 100644 --- a/x/crosschain/keeper/evm_deposit_test.go +++ b/x/crosschain/keeper/evm_deposit_test.go @@ -8,8 +8,8 @@ import ( "cosmossdk.io/math" evmtypes "github.com/evmos/ethermint/x/evm/types" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" - "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -41,8 +41,8 @@ func TestMsgServer_HandleEVMDeposit(t *testing.T) { }, nil, ) - require.NoError(t, err) - require.False(t, reverted) + assert.NoError(t, err) + assert.False(t, reverted) fungibleMock.AssertExpectations(t) }) @@ -70,8 +70,8 @@ func TestMsgServer_HandleEVMDeposit(t *testing.T) { }, nil, ) - require.ErrorIs(t, err, errDeposit) - require.False(t, reverted) + assert.ErrorIs(t, err, errDeposit) + assert.False(t, reverted) fungibleMock.AssertExpectations(t) }) @@ -114,8 +114,8 @@ func TestMsgServer_HandleEVMDeposit(t *testing.T) { }, senderChain, ) - require.NoError(t, err) - require.False(t, reverted) + assert.NoError(t, err) + assert.False(t, reverted) fungibleMock.AssertExpectations(t) }) @@ -159,8 +159,8 @@ func TestMsgServer_HandleEVMDeposit(t *testing.T) { }, senderChain, ) - require.ErrorIs(t, err, errDeposit) - require.False(t, reverted) + assert.ErrorIs(t, err, errDeposit) + assert.False(t, reverted) fungibleMock.AssertExpectations(t) }) @@ -204,8 +204,8 @@ func TestMsgServer_HandleEVMDeposit(t *testing.T) { }, senderChain, ) - require.ErrorIs(t, err, errDeposit) - require.True(t, reverted) + assert.ErrorIs(t, err, errDeposit) + assert.True(t, reverted) fungibleMock.AssertExpectations(t) }) @@ -248,8 +248,8 @@ func TestMsgServer_HandleEVMDeposit(t *testing.T) { }, senderChain, ) - require.ErrorIs(t, err, fungibletypes.ErrForeignCoinCapReached) - require.True(t, reverted) + assert.ErrorIs(t, err, fungibletypes.ErrForeignCoinCapReached) + assert.True(t, reverted) fungibleMock.AssertExpectations(t) }) @@ -292,8 +292,8 @@ func TestMsgServer_HandleEVMDeposit(t *testing.T) { }, senderChain, ) - require.ErrorIs(t, err, fungibletypes.ErrPausedZRC20) - require.True(t, reverted) + assert.ErrorIs(t, err, fungibletypes.ErrPausedZRC20) + assert.True(t, reverted) fungibleMock.AssertExpectations(t) }) @@ -334,8 +334,8 @@ func TestMsgServer_HandleEVMDeposit(t *testing.T) { }, senderChain, ) - require.ErrorIs(t, err, fungibletypes.ErrCallNonContract) - require.True(t, reverted) + assert.ErrorIs(t, err, fungibletypes.ErrCallNonContract) + assert.True(t, reverted) fungibleMock.AssertExpectations(t) }) @@ -358,7 +358,7 @@ func TestMsgServer_HandleEVMDeposit(t *testing.T) { }, senderChain, ) - require.ErrorIs(t, err, types.ErrUnableToParseAddress) + assert.ErrorIs(t, err, types.ErrUnableToParseAddress) }) t.Run("should deposit into address if address is parsed", func(t *testing.T) { @@ -373,7 +373,7 @@ func TestMsgServer_HandleEVMDeposit(t *testing.T) { amount := big.NewInt(42) data, err := hex.DecodeString("DEADBEEF") - require.NoError(t, err) + assert.NoError(t, err) fungibleMock.On( "ZRC20DepositAndCallContract", ctx, @@ -399,8 +399,8 @@ func TestMsgServer_HandleEVMDeposit(t *testing.T) { }, senderChain, ) - require.NoError(t, err) - require.False(t, reverted) + assert.NoError(t, err) + assert.False(t, reverted) fungibleMock.AssertExpectations(t) }) @@ -416,7 +416,7 @@ func TestMsgServer_HandleEVMDeposit(t *testing.T) { amount := big.NewInt(42) data, err := hex.DecodeString("DEADBEEF") - require.NoError(t, err) + assert.NoError(t, err) fungibleMock.On( "ZRC20DepositAndCallContract", ctx, @@ -442,8 +442,8 @@ func TestMsgServer_HandleEVMDeposit(t *testing.T) { }, senderChain, ) - require.NoError(t, err) - require.False(t, reverted) + assert.NoError(t, err) + assert.False(t, reverted) fungibleMock.AssertExpectations(t) }) diff --git a/x/crosschain/keeper/finalized_inbounds_test.go b/x/crosschain/keeper/finalized_inbounds_test.go index 9946024aa8..29cdf83b0e 100644 --- a/x/crosschain/keeper/finalized_inbounds_test.go +++ b/x/crosschain/keeper/finalized_inbounds_test.go @@ -3,7 +3,7 @@ package keeper_test import ( "testing" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/crosschain/types" @@ -16,14 +16,14 @@ func TestKeeper_IsFinalizedInbound(t *testing.T) { chainID := sample.Chain(5).ChainId eventIndex := sample.EventIndex() k.AddFinalizedInbound(ctx, intxHash, chainID, eventIndex) - require.True(t, k.IsFinalizedInbound(ctx, intxHash, chainID, eventIndex)) + assert.True(t, k.IsFinalizedInbound(ctx, intxHash, chainID, eventIndex)) }) t.Run("check false for non-finalized inbound", func(t *testing.T) { k, ctx, _, _ := keepertest.CrosschainKeeper(t) intxHash := sample.Hash().String() chainID := sample.Chain(5).ChainId eventIndex := sample.EventIndex() - require.False(t, k.IsFinalizedInbound(ctx, intxHash, chainID, eventIndex)) + assert.False(t, k.IsFinalizedInbound(ctx, intxHash, chainID, eventIndex)) }) t.Run("check true for finalized inbound list", func(t *testing.T) { k, ctx, _, _ := keepertest.CrosschainKeeper(t) @@ -38,7 +38,7 @@ func TestKeeper_IsFinalizedInbound(t *testing.T) { k.AddFinalizedInbound(ctx, txHashList[i], chainIdList[i], eventIndexList[i]) } for i := 0; i < listSize; i++ { - require.True(t, k.IsFinalizedInbound(ctx, txHashList[i], chainIdList[i], eventIndexList[i])) + assert.True(t, k.IsFinalizedInbound(ctx, txHashList[i], chainIdList[i], eventIndexList[i])) } }) } @@ -50,7 +50,7 @@ func TestKeeper_AddFinalizedInbound(t *testing.T) { chainID := sample.Chain(5).ChainId eventIndex := sample.EventIndex() k.AddFinalizedInbound(ctx, intxHash, chainID, eventIndex) - require.True(t, k.IsFinalizedInbound(ctx, intxHash, chainID, eventIndex)) + assert.True(t, k.IsFinalizedInbound(ctx, intxHash, chainID, eventIndex)) }) } @@ -58,7 +58,7 @@ func TestKeeper_GetAllFinalizedInbound(t *testing.T) { t.Run("check empty list", func(t *testing.T) { k, ctx, _, _ := keepertest.CrosschainKeeper(t) list := k.GetAllFinalizedInbound(ctx) - require.Empty(t, list) + assert.Empty(t, list) }) t.Run("check list", func(t *testing.T) { k, ctx, _, _ := keepertest.CrosschainKeeper(t) @@ -73,10 +73,10 @@ func TestKeeper_GetAllFinalizedInbound(t *testing.T) { k.AddFinalizedInbound(ctx, txHashList[i], chainIdList[i], eventIndexList[i]) } list := k.GetAllFinalizedInbound(ctx) - require.Equal(t, listSize, len(list)) + assert.Equal(t, listSize, len(list)) for i := 0; i < listSize; i++ { - require.Contains(t, list, types.FinalizedInboundKey(txHashList[i], chainIdList[i], eventIndexList[i])) + assert.Contains(t, list, types.FinalizedInboundKey(txHashList[i], chainIdList[i], eventIndexList[i])) } - require.NotContains(t, list, types.FinalizedInboundKey(sample.Hash().String(), sample.Chain(5).ChainId, sample.EventIndex())) + assert.NotContains(t, list, types.FinalizedInboundKey(sample.Hash().String(), sample.Chain(5).ChainId, sample.EventIndex())) }) } diff --git a/x/crosschain/keeper/gas_payment_test.go b/x/crosschain/keeper/gas_payment_test.go index d0a702daf5..b15b2065af 100644 --- a/x/crosschain/keeper/gas_payment_test.go +++ b/x/crosschain/keeper/gas_payment_test.go @@ -7,7 +7,7 @@ import ( "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" zetacommon "github.com/zeta-chain/zetacore/common" testkeeper "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -42,7 +42,7 @@ func TestKeeper_PayGasNativeAndUpdateCctx(t *testing.T) { sdk.UnwrapSDKContext(ctx), fungibletypes.NewMsgUpdateZRC20WithdrawFee(admin, zrc20.String(), sdk.NewUint(withdrawFee), math.Uint{}), ) - require.NoError(t, err) + assert.NoError(t, err) k.SetGasPrice(ctx, types.GasPrice{ ChainId: chainID, MedianIndex: 0, @@ -67,10 +67,10 @@ func TestKeeper_PayGasNativeAndUpdateCctx(t *testing.T) { // total fees must be 21000*2+1000=43000 // if the input amount of the cctx is 1e16, the output amount must be 1e16-43000=9999999999957000 err = k.PayGasNativeAndUpdateCctx(ctx, chainID, &cctx, math.NewUint(inputAmount)) - require.NoError(t, err) - require.Equal(t, uint64(9999999999957000), cctx.GetCurrentOutTxParam().Amount.Uint64()) - require.Equal(t, uint64(21_000), cctx.GetCurrentOutTxParam().OutboundTxGasLimit) - require.Equal(t, "2", cctx.GetCurrentOutTxParam().OutboundTxGasPrice) + assert.NoError(t, err) + assert.Equal(t, uint64(9999999999957000), cctx.GetCurrentOutTxParam().Amount.Uint64()) + assert.Equal(t, uint64(21_000), cctx.GetCurrentOutTxParam().OutboundTxGasLimit) + assert.Equal(t, "2", cctx.GetCurrentOutTxParam().OutboundTxGasPrice) }) t.Run("should fail if not coin type gas", func(t *testing.T) { @@ -82,7 +82,7 @@ func TestKeeper_PayGasNativeAndUpdateCctx(t *testing.T) { }, } err := k.PayGasNativeAndUpdateCctx(ctx, chainID, &cctx, math.NewUint(inputAmount)) - require.ErrorIs(t, err, types.ErrInvalidCoinType) + assert.ErrorIs(t, err, types.ErrInvalidCoinType) }) t.Run("should fail if chain is not supported", func(t *testing.T) { @@ -93,7 +93,7 @@ func TestKeeper_PayGasNativeAndUpdateCctx(t *testing.T) { }, } err := k.PayGasNativeAndUpdateCctx(ctx, 999999, &cctx, math.NewUint(inputAmount)) - require.ErrorIs(t, err, observertypes.ErrSupportedChains) + assert.ErrorIs(t, err, observertypes.ErrSupportedChains) }) t.Run("should fail if can't query the gas price", func(t *testing.T) { @@ -124,7 +124,7 @@ func TestKeeper_PayGasNativeAndUpdateCctx(t *testing.T) { } err := k.PayGasNativeAndUpdateCctx(ctx, chainID, &cctx, math.NewUint(inputAmount)) - require.ErrorIs(t, err, types.ErrCannotFindGasParams) + assert.ErrorIs(t, err, types.ErrCannotFindGasParams) }) t.Run("should fail if not enough amount for the fee", func(t *testing.T) { @@ -143,7 +143,7 @@ func TestKeeper_PayGasNativeAndUpdateCctx(t *testing.T) { sdk.UnwrapSDKContext(ctx), fungibletypes.NewMsgUpdateZRC20WithdrawFee(admin, zrc20.String(), sdk.NewUint(withdrawFee), math.Uint{}), ) - require.NoError(t, err) + assert.NoError(t, err) k.SetGasPrice(ctx, types.GasPrice{ ChainId: chainID, MedianIndex: 0, @@ -166,7 +166,7 @@ func TestKeeper_PayGasNativeAndUpdateCctx(t *testing.T) { // 42999 < 43000 err = k.PayGasNativeAndUpdateCctx(ctx, chainID, &cctx, math.NewUint(42999)) - require.ErrorIs(t, err, types.ErrNotEnoughGas) + assert.ErrorIs(t, err, types.ErrNotEnoughGas) }) } @@ -199,7 +199,7 @@ func TestKeeper_PayGasInERC20AndUpdateCctx(t *testing.T) { sdk.UnwrapSDKContext(ctx), fungibletypes.NewMsgUpdateZRC20WithdrawFee(admin, gasZRC20.String(), sdk.NewUint(withdrawFee), math.Uint{}), ) - require.NoError(t, err) + assert.NoError(t, err) k.SetGasPrice(ctx, types.GasPrice{ ChainId: chainID, MedianIndex: 0, @@ -233,15 +233,15 @@ func TestKeeper_PayGasInERC20AndUpdateCctx(t *testing.T) { // total fees in gas must be 21000*2+1000=43000 // we calculate what it represents in erc20 expectedInZeta, err := zk.FungibleKeeper.QueryUniswapV2RouterGetZetaAmountsIn(ctx, big.NewInt(43000), gasZRC20) - require.NoError(t, err) + assert.NoError(t, err) expectedInZRC20, err := zk.FungibleKeeper.QueryUniswapV2RouterGetZRC4AmountsIn(ctx, expectedInZeta, zrc20Addr) - require.NoError(t, err) + assert.NoError(t, err) err = k.PayGasInERC20AndUpdateCctx(ctx, chainID, &cctx, math.NewUint(inputAmount), false) - require.NoError(t, err) - require.Equal(t, inputAmount-expectedInZRC20.Uint64(), cctx.GetCurrentOutTxParam().Amount.Uint64()) - require.Equal(t, uint64(21_000), cctx.GetCurrentOutTxParam().OutboundTxGasLimit) - require.Equal(t, "2", cctx.GetCurrentOutTxParam().OutboundTxGasPrice) + assert.NoError(t, err) + assert.Equal(t, inputAmount-expectedInZRC20.Uint64(), cctx.GetCurrentOutTxParam().Amount.Uint64()) + assert.Equal(t, uint64(21_000), cctx.GetCurrentOutTxParam().OutboundTxGasLimit) + assert.Equal(t, "2", cctx.GetCurrentOutTxParam().OutboundTxGasPrice) }) t.Run("should fail if not coin type erc20", func(t *testing.T) { @@ -253,7 +253,7 @@ func TestKeeper_PayGasInERC20AndUpdateCctx(t *testing.T) { }, } err := k.PayGasInERC20AndUpdateCctx(ctx, chainID, &cctx, math.NewUint(inputAmount), false) - require.ErrorIs(t, err, types.ErrInvalidCoinType) + assert.ErrorIs(t, err, types.ErrInvalidCoinType) }) t.Run("should fail if chain is not supported", func(t *testing.T) { @@ -264,7 +264,7 @@ func TestKeeper_PayGasInERC20AndUpdateCctx(t *testing.T) { }, } err := k.PayGasInERC20AndUpdateCctx(ctx, 999999, &cctx, math.NewUint(inputAmount), false) - require.ErrorIs(t, err, observertypes.ErrSupportedChains) + assert.ErrorIs(t, err, observertypes.ErrSupportedChains) }) t.Run("should fail if can't query the gas price", func(t *testing.T) { @@ -295,7 +295,7 @@ func TestKeeper_PayGasInERC20AndUpdateCctx(t *testing.T) { } err := k.PayGasInERC20AndUpdateCctx(ctx, chainID, &cctx, math.NewUint(inputAmount), false) - require.ErrorIs(t, err, types.ErrCannotFindGasParams) + assert.ErrorIs(t, err, types.ErrCannotFindGasParams) }) t.Run("should fail if can't find the ZRC20", func(t *testing.T) { @@ -315,7 +315,7 @@ func TestKeeper_PayGasInERC20AndUpdateCctx(t *testing.T) { sdk.UnwrapSDKContext(ctx), fungibletypes.NewMsgUpdateZRC20WithdrawFee(admin, gasZRC20.String(), sdk.NewUint(withdrawFee), math.Uint{}), ) - require.NoError(t, err) + assert.NoError(t, err) k.SetGasPrice(ctx, types.GasPrice{ ChainId: chainID, MedianIndex: 0, @@ -341,7 +341,7 @@ func TestKeeper_PayGasInERC20AndUpdateCctx(t *testing.T) { } err = k.PayGasInERC20AndUpdateCctx(ctx, chainID, &cctx, math.NewUint(inputAmount), false) - require.ErrorIs(t, err, types.ErrForeignCoinNotFound) + assert.ErrorIs(t, err, types.ErrForeignCoinNotFound) }) t.Run("should fail if liquidity pool not setup", func(t *testing.T) { @@ -371,7 +371,7 @@ func TestKeeper_PayGasInERC20AndUpdateCctx(t *testing.T) { sdk.UnwrapSDKContext(ctx), fungibletypes.NewMsgUpdateZRC20WithdrawFee(admin, gasZRC20.String(), sdk.NewUint(withdrawFee), math.Uint{}), ) - require.NoError(t, err) + assert.NoError(t, err) k.SetGasPrice(ctx, types.GasPrice{ ChainId: chainID, MedianIndex: 0, @@ -397,7 +397,7 @@ func TestKeeper_PayGasInERC20AndUpdateCctx(t *testing.T) { } err = k.PayGasInERC20AndUpdateCctx(ctx, chainID, &cctx, math.NewUint(inputAmount), false) - require.ErrorIs(t, err, types.ErrNoLiquidityPool) + assert.ErrorIs(t, err, types.ErrNoLiquidityPool) }) t.Run("should fail if not enough amount for the fee", func(t *testing.T) { @@ -427,7 +427,7 @@ func TestKeeper_PayGasInERC20AndUpdateCctx(t *testing.T) { sdk.UnwrapSDKContext(ctx), fungibletypes.NewMsgUpdateZRC20WithdrawFee(admin, gasZRC20.String(), sdk.NewUint(withdrawFee), math.Uint{}), ) - require.NoError(t, err) + assert.NoError(t, err) k.SetGasPrice(ctx, types.GasPrice{ ChainId: chainID, MedianIndex: 0, @@ -461,13 +461,13 @@ func TestKeeper_PayGasInERC20AndUpdateCctx(t *testing.T) { // total fees in gas must be 21000*2+1000=43000 // we calculate what it represents in erc20 expectedInZeta, err := zk.FungibleKeeper.QueryUniswapV2RouterGetZetaAmountsIn(ctx, big.NewInt(43000), gasZRC20) - require.NoError(t, err) + assert.NoError(t, err) expectedInZRC20, err := zk.FungibleKeeper.QueryUniswapV2RouterGetZRC4AmountsIn(ctx, expectedInZeta, zrc20Addr) - require.NoError(t, err) + assert.NoError(t, err) // Provide expected value minus 1 err = k.PayGasInERC20AndUpdateCctx(ctx, chainID, &cctx, math.NewUintFromBigInt(expectedInZRC20).SubUint64(1), false) - require.ErrorIs(t, err, types.ErrNotEnoughGas) + assert.ErrorIs(t, err, types.ErrNotEnoughGas) }) } @@ -504,16 +504,16 @@ func TestKeeper_PayGasInZetaAndUpdateCctx(t *testing.T) { } // gasLimit * gasPrice * 2 = 1000 * 2 * 2 = 4000 expectedOutTxGasFeeInZeta, err := zk.FungibleKeeper.QueryUniswapV2RouterGetZetaAmountsIn(ctx, big.NewInt(4000), zrc20) - require.NoError(t, err) + assert.NoError(t, err) // the output amount must be input amount - (out tx fee in zeta + protocol flat fee) expectedFeeInZeta := types.GetProtocolFee().Add(math.NewUintFromBigInt(expectedOutTxGasFeeInZeta)) inputAmount := expectedFeeInZeta.Add(math.NewUint(100000)) err = k.PayGasInZetaAndUpdateCctx(ctx, chainID, &cctx, inputAmount, false) - require.NoError(t, err) - require.Equal(t, "100000", cctx.GetCurrentOutTxParam().Amount.String()) - require.Equal(t, "4", cctx.GetCurrentOutTxParam().OutboundTxGasPrice) // gas price is doubled - require.True(t, cctx.ZetaFees.Equal(expectedFeeInZeta.Add(math.NewUint(100))), "expected %s, got %s", expectedFeeInZeta.String(), cctx.ZetaFees.String()) + assert.NoError(t, err) + assert.Equal(t, "100000", cctx.GetCurrentOutTxParam().Amount.String()) + assert.Equal(t, "4", cctx.GetCurrentOutTxParam().OutboundTxGasPrice) // gas price is doubled + assert.True(t, cctx.ZetaFees.Equal(expectedFeeInZeta.Add(math.NewUint(100))), "expected %s, got %s", expectedFeeInZeta.String(), cctx.ZetaFees.String()) // can call with undefined zeta fees cctx = types.CrossChainTx{ @@ -528,14 +528,14 @@ func TestKeeper_PayGasInZetaAndUpdateCctx(t *testing.T) { }, } expectedOutTxGasFeeInZeta, err = zk.FungibleKeeper.QueryUniswapV2RouterGetZetaAmountsIn(ctx, big.NewInt(4000), zrc20) - require.NoError(t, err) + assert.NoError(t, err) expectedFeeInZeta = types.GetProtocolFee().Add(math.NewUintFromBigInt(expectedOutTxGasFeeInZeta)) inputAmount = expectedFeeInZeta.Add(math.NewUint(100000)) err = k.PayGasInZetaAndUpdateCctx(ctx, chainID, &cctx, inputAmount, false) - require.NoError(t, err) - require.Equal(t, "100000", cctx.GetCurrentOutTxParam().Amount.String()) - require.Equal(t, "4", cctx.GetCurrentOutTxParam().OutboundTxGasPrice) // gas price is doubled - require.True(t, cctx.ZetaFees.Equal(expectedFeeInZeta), "expected %s, got %s", expectedFeeInZeta.String(), cctx.ZetaFees.String()) + assert.NoError(t, err) + assert.Equal(t, "100000", cctx.GetCurrentOutTxParam().Amount.String()) + assert.Equal(t, "4", cctx.GetCurrentOutTxParam().OutboundTxGasPrice) // gas price is doubled + assert.True(t, cctx.ZetaFees.Equal(expectedFeeInZeta), "expected %s, got %s", expectedFeeInZeta.String(), cctx.ZetaFees.String()) }) t.Run("should fail if pay gas in zeta with coin type other than zeta", func(t *testing.T) { @@ -547,7 +547,7 @@ func TestKeeper_PayGasInZetaAndUpdateCctx(t *testing.T) { }, } err := k.PayGasInZetaAndUpdateCctx(ctx, chainID, &cctx, math.NewUint(100000), false) - require.ErrorIs(t, err, types.ErrInvalidCoinType) + assert.ErrorIs(t, err, types.ErrInvalidCoinType) }) t.Run("should fail if chain is not supported", func(t *testing.T) { @@ -558,7 +558,7 @@ func TestKeeper_PayGasInZetaAndUpdateCctx(t *testing.T) { }, } err := k.PayGasInZetaAndUpdateCctx(ctx, 999999, &cctx, math.NewUint(100000), false) - require.ErrorIs(t, err, observertypes.ErrSupportedChains) + assert.ErrorIs(t, err, observertypes.ErrSupportedChains) }) t.Run("should fail if can't query the gas price", func(t *testing.T) { @@ -589,7 +589,7 @@ func TestKeeper_PayGasInZetaAndUpdateCctx(t *testing.T) { } err := k.PayGasInZetaAndUpdateCctx(ctx, chainID, &cctx, math.NewUint(100000), false) - require.ErrorIs(t, err, types.ErrUnableToGetGasPrice) + assert.ErrorIs(t, err, types.ErrUnableToGetGasPrice) }) t.Run("should fail if not enough amount for the fee", func(t *testing.T) { @@ -623,12 +623,12 @@ func TestKeeper_PayGasInZetaAndUpdateCctx(t *testing.T) { ZetaFees: math.NewUint(100), } expectedOutTxGasFeeInZeta, err := zk.FungibleKeeper.QueryUniswapV2RouterGetZetaAmountsIn(ctx, big.NewInt(4000), zrc20) - require.NoError(t, err) + assert.NoError(t, err) expectedFeeInZeta := types.GetProtocolFee().Add(math.NewUintFromBigInt(expectedOutTxGasFeeInZeta)) // set input amount lower than total zeta fee inputAmount := expectedFeeInZeta.Sub(math.NewUint(1)) err = k.PayGasInZetaAndUpdateCctx(ctx, chainID, &cctx, inputAmount, false) - require.ErrorIs(t, err, types.ErrNotEnoughZetaBurnt) + assert.ErrorIs(t, err, types.ErrNotEnoughZetaBurnt) }) } diff --git a/x/crosschain/keeper/grpc_query_cctx_test.go b/x/crosschain/keeper/grpc_query_cctx_test.go index cd5d1e3c14..63b47e7f50 100644 --- a/x/crosschain/keeper/grpc_query_cctx_test.go +++ b/x/crosschain/keeper/grpc_query_cctx_test.go @@ -5,7 +5,7 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/crosschain/keeper" @@ -68,19 +68,19 @@ func TestKeeper_CctxListPending(t *testing.T) { t.Run("should fail for empty req", func(t *testing.T) { k, ctx, _, _ := keepertest.CrosschainKeeper(t) _, err := k.CctxListPending(ctx, nil) - require.ErrorContains(t, err, "invalid request") + assert.ErrorContains(t, err, "invalid request") }) t.Run("should fail if limit is too high", func(t *testing.T) { k, ctx, _, _ := keepertest.CrosschainKeeper(t) _, err := k.CctxListPending(ctx, &types.QueryListCctxPendingRequest{Limit: keeper.MaxPendingCctxs + 1}) - require.ErrorContains(t, err, "limit exceeds max limit of") + assert.ErrorContains(t, err, "limit exceeds max limit of") }) t.Run("should fail if no TSS", func(t *testing.T) { k, ctx, _, _ := keepertest.CrosschainKeeper(t) _, err := k.CctxListPending(ctx, &types.QueryListCctxPendingRequest{Limit: 1}) - require.ErrorContains(t, err, "tss not found") + assert.ErrorContains(t, err, "tss not found") }) t.Run("should return empty list if no nonces", func(t *testing.T) { @@ -90,7 +90,7 @@ func TestKeeper_CctxListPending(t *testing.T) { zk.ObserverKeeper.SetTSS(ctx, sample.Tss()) _, err := k.CctxListPending(ctx, &types.QueryListCctxPendingRequest{Limit: 1}) - require.ErrorContains(t, err, "pending nonces not found") + assert.ErrorContains(t, err, "pending nonces not found") }) t.Run("can retrieve pending cctx in range", func(t *testing.T) { @@ -101,16 +101,16 @@ func TestKeeper_CctxListPending(t *testing.T) { cctxs := createCctxWithNonceRange(t, ctx, *k, 1000, 2000, chainID, tss, zk) res, err := k.CctxListPending(ctx, &types.QueryListCctxPendingRequest{ChainId: chainID, Limit: 100}) - require.NoError(t, err) - require.Equal(t, 100, len(res.CrossChainTx)) - require.EqualValues(t, cctxs[0:100], res.CrossChainTx) - require.EqualValues(t, uint64(1000), res.TotalPending) + assert.NoError(t, err) + assert.Equal(t, 100, len(res.CrossChainTx)) + assert.EqualValues(t, cctxs[0:100], res.CrossChainTx) + assert.EqualValues(t, uint64(1000), res.TotalPending) res, err = k.CctxListPending(ctx, &types.QueryListCctxPendingRequest{ChainId: chainID}) - require.NoError(t, err) - require.Equal(t, keeper.MaxPendingCctxs, len(res.CrossChainTx)) - require.EqualValues(t, cctxs[0:keeper.MaxPendingCctxs], res.CrossChainTx) - require.EqualValues(t, uint64(1000), res.TotalPending) + assert.NoError(t, err) + assert.Equal(t, keeper.MaxPendingCctxs, len(res.CrossChainTx)) + assert.EqualValues(t, cctxs[0:keeper.MaxPendingCctxs], res.CrossChainTx) + assert.EqualValues(t, uint64(1000), res.TotalPending) }) t.Run("can retrieve pending cctx with range smaller than max", func(t *testing.T) { @@ -121,10 +121,10 @@ func TestKeeper_CctxListPending(t *testing.T) { cctxs := createCctxWithNonceRange(t, ctx, *k, 1000, 1100, chainID, tss, zk) res, err := k.CctxListPending(ctx, &types.QueryListCctxPendingRequest{ChainId: chainID}) - require.NoError(t, err) - require.Equal(t, 100, len(res.CrossChainTx)) - require.EqualValues(t, cctxs, res.CrossChainTx) - require.EqualValues(t, uint64(100), res.TotalPending) + assert.NoError(t, err) + assert.Equal(t, 100, len(res.CrossChainTx)) + assert.EqualValues(t, cctxs, res.CrossChainTx) + assert.EqualValues(t, uint64(100), res.TotalPending) }) t.Run("can retrieve pending cctx with pending cctx below nonce low", func(t *testing.T) { @@ -136,23 +136,23 @@ func TestKeeper_CctxListPending(t *testing.T) { // set some cctxs as pending below nonce cctx1, found := k.GetCrossChainTx(ctx, "940") - require.True(t, found) + assert.True(t, found) cctx1.CctxStatus.Status = types.CctxStatus_PendingOutbound k.SetCrossChainTx(ctx, cctx1) cctx2, found := k.GetCrossChainTx(ctx, "955") - require.True(t, found) + assert.True(t, found) cctx2.CctxStatus.Status = types.CctxStatus_PendingOutbound k.SetCrossChainTx(ctx, cctx2) res, err := k.CctxListPending(ctx, &types.QueryListCctxPendingRequest{ChainId: chainID, Limit: 100}) - require.NoError(t, err) - require.Equal(t, 100, len(res.CrossChainTx)) + assert.NoError(t, err) + assert.Equal(t, 100, len(res.CrossChainTx)) expectedCctxs := append([]*types.CrossChainTx{&cctx1, &cctx2}, cctxs[0:98]...) - require.EqualValues(t, expectedCctxs, res.CrossChainTx) + assert.EqualValues(t, expectedCctxs, res.CrossChainTx) // pending nonce + 2 - require.EqualValues(t, uint64(1002), res.TotalPending) + assert.EqualValues(t, uint64(1002), res.TotalPending) }) } diff --git a/x/crosschain/keeper/grpc_query_gas_price_test.go b/x/crosschain/keeper/grpc_query_gas_price_test.go index 5c2d12cadd..7b4a88cf0c 100644 --- a/x/crosschain/keeper/grpc_query_gas_price_test.go +++ b/x/crosschain/keeper/grpc_query_gas_price_test.go @@ -6,7 +6,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/x/crosschain/types" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -46,9 +45,9 @@ func TestGasPriceQuerySingle(t *testing.T) { t.Run(tc.desc, func(t *testing.T) { response, err := keeper.GasPrice(wctx, tc.request) if tc.err != nil { - require.ErrorIs(t, err, tc.err) + assert.ErrorIs(t, err, tc.err) } else { - require.Equal(t, tc.response, response) + assert.Equal(t, tc.response, response) } }) } @@ -73,7 +72,7 @@ func TestGasPriceQueryPaginated(t *testing.T) { step := 2 for i := 0; i < len(msgs); i += step { resp, err := keeper.GasPriceAll(wctx, request(nil, uint64(i), uint64(step), false)) - require.NoError(t, err) + assert.NoError(t, err) for j := i; j < len(msgs) && j < i+step; j++ { assert.Equal(t, &msgs[j], resp.GasPrice[j-i]) } @@ -84,7 +83,7 @@ func TestGasPriceQueryPaginated(t *testing.T) { var next []byte for i := 0; i < len(msgs); i += step { resp, err := keeper.GasPriceAll(wctx, request(next, 0, uint64(step), false)) - require.NoError(t, err) + assert.NoError(t, err) for j := i; j < len(msgs) && j < i+step; j++ { assert.Equal(t, &msgs[j], resp.GasPrice[j-i]) } @@ -93,11 +92,11 @@ func TestGasPriceQueryPaginated(t *testing.T) { }) t.Run("Total", func(t *testing.T) { resp, err := keeper.GasPriceAll(wctx, request(nil, 0, 0, true)) - require.NoError(t, err) - require.Equal(t, len(msgs), int(resp.Pagination.Total)) + assert.NoError(t, err) + assert.Equal(t, len(msgs), int(resp.Pagination.Total)) }) t.Run("InvalidRequest", func(t *testing.T) { _, err := keeper.GasPriceAll(wctx, nil) - require.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) + assert.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) }) } diff --git a/x/crosschain/keeper/grpc_query_in_tx_hash_to_cctx_test.go b/x/crosschain/keeper/grpc_query_in_tx_hash_to_cctx_test.go index 5704fdc54a..6d00f1b562 100644 --- a/x/crosschain/keeper/grpc_query_in_tx_hash_to_cctx_test.go +++ b/x/crosschain/keeper/grpc_query_in_tx_hash_to_cctx_test.go @@ -9,7 +9,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -58,10 +58,10 @@ func TestInTxHashToCctxQuerySingle(t *testing.T) { t.Run(tc.desc, func(t *testing.T) { response, err := keeper.InTxHashToCctx(wctx, tc.request) if tc.err != nil { - require.ErrorIs(t, err, tc.err) + assert.ErrorIs(t, err, tc.err) } else { - require.NoError(t, err) - require.Equal(t, + assert.NoError(t, err) + assert.Equal(t, nullify.Fill(tc.response), nullify.Fill(response), ) @@ -89,9 +89,9 @@ func TestInTxHashToCctxQueryPaginated(t *testing.T) { step := 2 for i := 0; i < len(msgs); i += step { resp, err := keeper.InTxHashToCctxAll(wctx, request(nil, uint64(i), uint64(step), false)) - require.NoError(t, err) - require.LessOrEqual(t, len(resp.InTxHashToCctx), step) - require.Subset(t, + assert.NoError(t, err) + assert.LessOrEqual(t, len(resp.InTxHashToCctx), step) + assert.Subset(t, nullify.Fill(msgs), nullify.Fill(resp.InTxHashToCctx), ) @@ -102,9 +102,9 @@ func TestInTxHashToCctxQueryPaginated(t *testing.T) { var next []byte for i := 0; i < len(msgs); i += step { resp, err := keeper.InTxHashToCctxAll(wctx, request(next, 0, uint64(step), false)) - require.NoError(t, err) - require.LessOrEqual(t, len(resp.InTxHashToCctx), step) - require.Subset(t, + assert.NoError(t, err) + assert.LessOrEqual(t, len(resp.InTxHashToCctx), step) + assert.Subset(t, nullify.Fill(msgs), nullify.Fill(resp.InTxHashToCctx), ) @@ -113,16 +113,16 @@ func TestInTxHashToCctxQueryPaginated(t *testing.T) { }) t.Run("Total", func(t *testing.T) { resp, err := keeper.InTxHashToCctxAll(wctx, request(nil, 0, 0, true)) - require.NoError(t, err) - require.Equal(t, len(msgs), int(resp.Pagination.Total)) - require.ElementsMatch(t, + assert.NoError(t, err) + assert.Equal(t, len(msgs), int(resp.Pagination.Total)) + assert.ElementsMatch(t, nullify.Fill(msgs), nullify.Fill(resp.InTxHashToCctx), ) }) t.Run("InvalidRequest", func(t *testing.T) { _, err := keeper.InTxHashToCctxAll(wctx, nil) - require.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) + assert.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) }) } @@ -157,10 +157,10 @@ func TestKeeper_InTxHashToCctxDataQuery(t *testing.T) { InTxHash: inTxHashToCctx.InTxHash, } res, err := keeper.InTxHashToCctxData(wctx, req) - require.NoError(t, err) - require.Equal(t, len(cctxs), len(res.CrossChainTxs)) + assert.NoError(t, err) + assert.Equal(t, len(cctxs), len(res.CrossChainTxs)) for i := range cctxs { - require.Equal(t, nullify.Fill(cctxs[i]), nullify.Fill(res.CrossChainTxs[i])) + assert.Equal(t, nullify.Fill(cctxs[i]), nullify.Fill(res.CrossChainTxs[i])) } }) t.Run("in tx hash not found", func(t *testing.T) { @@ -168,7 +168,7 @@ func TestKeeper_InTxHashToCctxDataQuery(t *testing.T) { InTxHash: "notfound", } _, err := keeper.InTxHashToCctxData(wctx, req) - require.ErrorIs(t, err, status.Error(codes.NotFound, "not found")) + assert.ErrorIs(t, err, status.Error(codes.NotFound, "not found")) }) t.Run("cctx not indexed return internal error", func(t *testing.T) { keeper.SetInTxHashToCctx(ctx, types.InTxHashToCctx{ @@ -180,6 +180,6 @@ func TestKeeper_InTxHashToCctxDataQuery(t *testing.T) { InTxHash: "nocctx", } _, err := keeper.InTxHashToCctxData(wctx, req) - require.ErrorIs(t, err, status.Error(codes.Internal, "cctx indexed notfound doesn't exist")) + assert.ErrorIs(t, err, status.Error(codes.Internal, "cctx indexed notfound doesn't exist")) }) } diff --git a/x/crosschain/keeper/grpc_query_last_block_height_test.go b/x/crosschain/keeper/grpc_query_last_block_height_test.go index b2fd0463cf..428a246a61 100644 --- a/x/crosschain/keeper/grpc_query_last_block_height_test.go +++ b/x/crosschain/keeper/grpc_query_last_block_height_test.go @@ -6,7 +6,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/x/crosschain/types" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -46,9 +45,9 @@ func TestLastBlockHeightQuerySingle(t *testing.T) { t.Run(tc.desc, func(t *testing.T) { response, err := keeper.LastBlockHeight(wctx, tc.request) if tc.err != nil { - require.ErrorIs(t, err, tc.err) + assert.ErrorIs(t, err, tc.err) } else { - require.Equal(t, tc.response, response) + assert.Equal(t, tc.response, response) } }) } @@ -73,7 +72,7 @@ func TestLastBlockHeightQueryPaginated(t *testing.T) { step := 2 for i := 0; i < len(msgs); i += step { resp, err := keeper.LastBlockHeightAll(wctx, request(nil, uint64(i), uint64(step), false)) - require.NoError(t, err) + assert.NoError(t, err) for j := i; j < len(msgs) && j < i+step; j++ { assert.Equal(t, &msgs[j], resp.LastBlockHeight[j-i]) } @@ -84,7 +83,7 @@ func TestLastBlockHeightQueryPaginated(t *testing.T) { var next []byte for i := 0; i < len(msgs); i += step { resp, err := keeper.LastBlockHeightAll(wctx, request(next, 0, uint64(step), false)) - require.NoError(t, err) + assert.NoError(t, err) for j := i; j < len(msgs) && j < i+step; j++ { assert.Equal(t, &msgs[j], resp.LastBlockHeight[j-i]) } @@ -93,11 +92,11 @@ func TestLastBlockHeightQueryPaginated(t *testing.T) { }) t.Run("Total", func(t *testing.T) { resp, err := keeper.LastBlockHeightAll(wctx, request(nil, 0, 0, true)) - require.NoError(t, err) - require.Equal(t, len(msgs), int(resp.Pagination.Total)) + assert.NoError(t, err) + assert.Equal(t, len(msgs), int(resp.Pagination.Total)) }) t.Run("InvalidRequest", func(t *testing.T) { _, err := keeper.LastBlockHeightAll(wctx, nil) - require.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) + assert.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) }) } diff --git a/x/crosschain/keeper/grpc_query_out_tx_tracker_test.go b/x/crosschain/keeper/grpc_query_out_tx_tracker_test.go index 39f5ad3673..5951acf881 100644 --- a/x/crosschain/keeper/grpc_query_out_tx_tracker_test.go +++ b/x/crosschain/keeper/grpc_query_out_tx_tracker_test.go @@ -39,10 +39,10 @@ package keeper_test // t.Run(tc.desc, func(t *testing.T) { // response, err := keeper.OutTxTracker(wctx, tc.request) // if tc.err != nil { -// require.ErrorIs(t, err, tc.err) +// assert.ErrorIs(t, err, tc.err) // } else { -// require.NoError(t, err) -// require.Equal(t, +// assert.NoError(t, err) +// assert.Equal(t, // nullify.Fill(tc.response), // nullify.Fill(response), // ) @@ -70,9 +70,9 @@ package keeper_test // step := 2 // for i := 0; i < len(msgs); i += step { // resp, err := keeper.OutTxTrackerAll(wctx, request(nil, uint64(i), uint64(step), false)) -// require.NoError(t, err) -// require.LessOrEqual(t, len(resp.OutTxTracker), step) -// require.Subset(t, +// assert.NoError(t, err) +// assert.LessOrEqual(t, len(resp.OutTxTracker), step) +// assert.Subset(t, // nullify.Fill(msgs), // nullify.Fill(resp.OutTxTracker), // ) @@ -83,9 +83,9 @@ package keeper_test // var next []byte // for i := 0; i < len(msgs); i += step { // resp, err := keeper.OutTxTrackerAll(wctx, request(next, 0, uint64(step), false)) -// require.NoError(t, err) -// require.LessOrEqual(t, len(resp.OutTxTracker), step) -// require.Subset(t, +// assert.NoError(t, err) +// assert.LessOrEqual(t, len(resp.OutTxTracker), step) +// assert.Subset(t, // nullify.Fill(msgs), // nullify.Fill(resp.OutTxTracker), // ) @@ -94,15 +94,15 @@ package keeper_test // }) // t.Run("Total", func(t *testing.T) { // resp, err := keeper.OutTxTrackerAll(wctx, request(nil, 0, 0, true)) -// require.NoError(t, err) -// require.Equal(t, len(msgs), int(resp.Pagination.Total)) -// require.ElementsMatch(t, +// assert.NoError(t, err) +// assert.Equal(t, len(msgs), int(resp.Pagination.Total)) +// assert.ElementsMatch(t, // nullify.Fill(msgs), // nullify.Fill(resp.OutTxTracker), // ) // }) // t.Run("InvalidRequest", func(t *testing.T) { // _, err := keeper.OutTxTrackerAll(wctx, nil) -// require.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) +// assert.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) // }) //} diff --git a/x/crosschain/keeper/in_tx_hash_to_cctx_test.go b/x/crosschain/keeper/in_tx_hash_to_cctx_test.go index 6eb0118cf9..2084724f44 100644 --- a/x/crosschain/keeper/in_tx_hash_to_cctx_test.go +++ b/x/crosschain/keeper/in_tx_hash_to_cctx_test.go @@ -7,7 +7,7 @@ import ( "github.com/zeta-chain/zetacore/x/crosschain/keeper" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/nullify" "github.com/zeta-chain/zetacore/x/crosschain/types" @@ -30,8 +30,8 @@ func TestInTxHashToCctxGet(t *testing.T) { rst, found := keeper.GetInTxHashToCctx(ctx, item.InTxHash, ) - require.True(t, found) - require.Equal(t, + assert.True(t, found) + assert.Equal(t, nullify.Fill(&item), nullify.Fill(&rst), ) @@ -47,14 +47,14 @@ func TestInTxHashToCctxRemove(t *testing.T) { _, found := keeper.GetInTxHashToCctx(ctx, item.InTxHash, ) - require.False(t, found) + assert.False(t, found) } } func TestInTxHashToCctxGetAll(t *testing.T) { keeper, ctx, _, _ := keepertest.CrosschainKeeper(t) items := createNInTxHashToCctx(keeper, ctx, 10) - require.ElementsMatch(t, + assert.ElementsMatch(t, nullify.Fill(items), nullify.Fill(keeper.GetAllInTxHashToCctx(ctx)), ) diff --git a/x/crosschain/keeper/in_tx_tracker_test.go b/x/crosschain/keeper/in_tx_tracker_test.go index a4bda41192..841e4a2326 100644 --- a/x/crosschain/keeper/in_tx_tracker_test.go +++ b/x/crosschain/keeper/in_tx_tracker_test.go @@ -7,7 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/common" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/nullify" @@ -31,15 +31,15 @@ func TestKeeper_GetAllInTxTrackerForChain(t *testing.T) { intxTrackers := createNInTxTracker(keeper, ctx, 10, 5) for _, item := range intxTrackers { rst, found := keeper.GetInTxTracker(ctx, item.ChainId, item.TxHash) - require.True(t, found) - require.Equal(t, item, rst) + assert.True(t, found) + assert.Equal(t, item, rst) } }) t.Run("Get all InTx trackers", func(t *testing.T) { keeper, ctx, _, _ := keepertest.CrosschainKeeper(t) intxTrackers := createNInTxTracker(keeper, ctx, 10, 5) rst := keeper.GetAllInTxTracker(ctx) - require.Equal(t, intxTrackers, rst) + assert.Equal(t, intxTrackers, rst) }) t.Run("Get all InTx trackers for chain", func(t *testing.T) { keeper, ctx, _, _ := keepertest.CrosschainKeeper(t) @@ -51,39 +51,39 @@ func TestKeeper_GetAllInTxTrackerForChain(t *testing.T) { sort.SliceStable(intxTrackersNew, func(i, j int) bool { return intxTrackersNew[i].TxHash < intxTrackersNew[j].TxHash }) - require.Equal(t, intxTrackersNew, rst) + assert.Equal(t, intxTrackersNew, rst) }) t.Run("Get all InTx trackers for chain paginated by limit", func(t *testing.T) { keeper, ctx, _, _ := keepertest.CrosschainKeeper(t) intxTrackers := createNInTxTracker(keeper, ctx, 100, 6) rst, pageRes, err := keeper.GetAllInTxTrackerForChainPaginated(ctx, 6, &query.PageRequest{Limit: 10, CountTotal: true}) - require.NoError(t, err) - require.Subset(t, nullify.Fill(intxTrackers), nullify.Fill(rst)) - require.Equal(t, len(intxTrackers), int(pageRes.Total)) + assert.NoError(t, err) + assert.Subset(t, nullify.Fill(intxTrackers), nullify.Fill(rst)) + assert.Equal(t, len(intxTrackers), int(pageRes.Total)) }) t.Run("Get all InTx trackers for chain paginated by offset", func(t *testing.T) { keeper, ctx, _, _ := keepertest.CrosschainKeeper(t) intxTrackers := createNInTxTracker(keeper, ctx, 100, 6) rst, pageRes, err := keeper.GetAllInTxTrackerForChainPaginated(ctx, 6, &query.PageRequest{Offset: 10, CountTotal: true}) - require.NoError(t, err) - require.Subset(t, nullify.Fill(intxTrackers), nullify.Fill(rst)) - require.Equal(t, len(intxTrackers), int(pageRes.Total)) + assert.NoError(t, err) + assert.Subset(t, nullify.Fill(intxTrackers), nullify.Fill(rst)) + assert.Equal(t, len(intxTrackers), int(pageRes.Total)) }) t.Run("Get all InTx trackers paginated by limit", func(t *testing.T) { keeper, ctx, _, _ := keepertest.CrosschainKeeper(t) intxTrackers := append(createNInTxTracker(keeper, ctx, 10, 6), createNInTxTracker(keeper, ctx, 10, 7)...) rst, pageRes, err := keeper.GetAllInTxTrackerPaginated(ctx, &query.PageRequest{Limit: 20, CountTotal: true}) - require.NoError(t, err) - require.Subset(t, nullify.Fill(intxTrackers), nullify.Fill(rst)) - require.Equal(t, len(intxTrackers), int(pageRes.Total)) + assert.NoError(t, err) + assert.Subset(t, nullify.Fill(intxTrackers), nullify.Fill(rst)) + assert.Equal(t, len(intxTrackers), int(pageRes.Total)) }) t.Run("Get all InTx trackers paginated by offset", func(t *testing.T) { keeper, ctx, _, _ := keepertest.CrosschainKeeper(t) intxTrackers := append(createNInTxTracker(keeper, ctx, 100, 6), createNInTxTracker(keeper, ctx, 100, 7)...) rst, pageRes, err := keeper.GetAllInTxTrackerPaginated(ctx, &query.PageRequest{Offset: 10, CountTotal: true}) - require.NoError(t, err) - require.Subset(t, nullify.Fill(intxTrackers), nullify.Fill(rst)) - require.Equal(t, len(intxTrackers), int(pageRes.Total)) + assert.NoError(t, err) + assert.Subset(t, nullify.Fill(intxTrackers), nullify.Fill(rst)) + assert.Equal(t, len(intxTrackers), int(pageRes.Total)) }) t.Run("Delete InTxTracker", func(t *testing.T) { keeper, ctx, _, _ := keepertest.CrosschainKeeper(t) @@ -98,6 +98,6 @@ func TestKeeper_GetAllInTxTrackerForChain(t *testing.T) { keeper.RemoveInTxTrackerIfExists(ctx, item.ChainId, item.TxHash) } rst := keeper.GetAllInTxTrackerForChain(ctx, 6) - require.Equal(t, 0, len(rst)) + assert.Equal(t, 0, len(rst)) }) } diff --git a/x/crosschain/keeper/keeper_test.go b/x/crosschain/keeper/keeper_test.go index 3a65063a16..7bc0af5fb1 100644 --- a/x/crosschain/keeper/keeper_test.go +++ b/x/crosschain/keeper/keeper_test.go @@ -12,7 +12,7 @@ import ( bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" typesparams "github.com/cosmos/cosmos-sdk/x/params/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmdb "github.com/tendermint/tm-db" @@ -29,7 +29,7 @@ func setupKeeper(t testing.TB) (*Keeper, sdk.Context) { stateStore := store.NewCommitMultiStore(db) stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db) stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil) - require.NoError(t, stateStore.LoadLatestVersion()) + assert.NoError(t, stateStore.LoadLatestVersion()) registry := codectypes.NewInterfaceRegistry() cdc := codec.NewProtoCodec(registry) diff --git a/x/crosschain/keeper/msg_server_abort_stuck_cctx_test.go b/x/crosschain/keeper/msg_server_abort_stuck_cctx_test.go index f9b7c380e0..8a1953d3b8 100644 --- a/x/crosschain/keeper/msg_server_abort_stuck_cctx_test.go +++ b/x/crosschain/keeper/msg_server_abort_stuck_cctx_test.go @@ -3,7 +3,7 @@ package keeper_test import ( "testing" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" crosschainkeeper "github.com/zeta-chain/zetacore/x/crosschain/keeper" @@ -32,11 +32,11 @@ func TestMsgServer_AbortStuckCCTX(t *testing.T) { CctxIndex: "cctx_index", }) - require.NoError(t, err) + assert.NoError(t, err) cctxFound, found := k.GetCrossChainTx(ctx, "cctx_index") - require.True(t, found) - require.Equal(t, crosschaintypes.CctxStatus_Aborted, cctxFound.CctxStatus.Status) - require.Equal(t, crosschainkeeper.AbortMessage, cctxFound.CctxStatus.StatusMessage) + assert.True(t, found) + assert.Equal(t, crosschaintypes.CctxStatus_Aborted, cctxFound.CctxStatus.Status) + assert.Equal(t, crosschainkeeper.AbortMessage, cctxFound.CctxStatus.StatusMessage) }) t.Run("can abort a cctx in pending outbound", func(t *testing.T) { @@ -59,11 +59,11 @@ func TestMsgServer_AbortStuckCCTX(t *testing.T) { CctxIndex: "cctx_index", }) - require.NoError(t, err) + assert.NoError(t, err) cctxFound, found := k.GetCrossChainTx(ctx, "cctx_index") - require.True(t, found) - require.Equal(t, crosschaintypes.CctxStatus_Aborted, cctxFound.CctxStatus.Status) - require.Equal(t, crosschainkeeper.AbortMessage, cctxFound.CctxStatus.StatusMessage) + assert.True(t, found) + assert.Equal(t, crosschaintypes.CctxStatus_Aborted, cctxFound.CctxStatus.Status) + assert.Equal(t, crosschainkeeper.AbortMessage, cctxFound.CctxStatus.StatusMessage) }) t.Run("can abort a cctx in pending revert", func(t *testing.T) { @@ -86,11 +86,11 @@ func TestMsgServer_AbortStuckCCTX(t *testing.T) { CctxIndex: "cctx_index", }) - require.NoError(t, err) + assert.NoError(t, err) cctxFound, found := k.GetCrossChainTx(ctx, "cctx_index") - require.True(t, found) - require.Equal(t, crosschaintypes.CctxStatus_Aborted, cctxFound.CctxStatus.Status) - require.Equal(t, crosschainkeeper.AbortMessage, cctxFound.CctxStatus.StatusMessage) + assert.True(t, found) + assert.Equal(t, crosschaintypes.CctxStatus_Aborted, cctxFound.CctxStatus.Status) + assert.Equal(t, crosschainkeeper.AbortMessage, cctxFound.CctxStatus.StatusMessage) }) t.Run("cannot abort a cctx in pending outbound if not admin", func(t *testing.T) { @@ -110,7 +110,7 @@ func TestMsgServer_AbortStuckCCTX(t *testing.T) { Creator: sample.AccAddress(), CctxIndex: "cctx_index", }) - require.ErrorIs(t, err, observertypes.ErrNotAuthorized) + assert.ErrorIs(t, err, observertypes.ErrNotAuthorized) }) t.Run("cannot abort a cctx if doesn't exist", func(t *testing.T) { @@ -124,7 +124,7 @@ func TestMsgServer_AbortStuckCCTX(t *testing.T) { Creator: admin, CctxIndex: "cctx_index", }) - require.ErrorIs(t, err, crosschaintypes.ErrCannotFindCctx) + assert.ErrorIs(t, err, crosschaintypes.ErrCannotFindCctx) }) t.Run("cannot abort a cctx if not pending", func(t *testing.T) { @@ -146,6 +146,6 @@ func TestMsgServer_AbortStuckCCTX(t *testing.T) { Creator: admin, CctxIndex: "cctx_index", }) - require.ErrorIs(t, err, crosschaintypes.ErrStatusNotPending) + assert.ErrorIs(t, err, crosschaintypes.ErrStatusNotPending) }) } diff --git a/x/crosschain/keeper/msg_server_add_to_intx_tracker_test.go b/x/crosschain/keeper/msg_server_add_to_intx_tracker_test.go index 7457068b38..f2b646017a 100644 --- a/x/crosschain/keeper/msg_server_add_to_intx_tracker_test.go +++ b/x/crosschain/keeper/msg_server_add_to_intx_tracker_test.go @@ -5,7 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ethtypes "github.com/ethereum/go-ethereum/core/types" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/common" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -19,7 +19,7 @@ func TestMsgServer_AddToInTxTracker(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) chainID := int64(5) txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() - require.NoError(t, err) + assert.NoError(t, err) setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) msgServer := keeper.NewMsgServerImpl(*k) _, err = msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ @@ -31,16 +31,16 @@ func TestMsgServer_AddToInTxTracker(t *testing.T) { BlockHash: block.Hash().Hex(), TxIndex: txIndex, }) - require.NoError(t, err) + assert.NoError(t, err) _, found := k.GetInTxTracker(ctx, chainID, tx.Hash().Hex()) - require.True(t, found) + assert.True(t, found) }) t.Run("fail to add proof based tracker with wrong tx hash", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) chainID := getValidEthChainID(t) txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() - require.NoError(t, err) + assert.NoError(t, err) setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) msgServer := keeper.NewMsgServerImpl(*k) _, err = msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ @@ -52,16 +52,16 @@ func TestMsgServer_AddToInTxTracker(t *testing.T) { BlockHash: block.Hash().Hex(), TxIndex: txIndex, }) - require.ErrorIs(t, err, types.ErrTxBodyVerificationFail) + assert.ErrorIs(t, err, types.ErrTxBodyVerificationFail) _, found := k.GetInTxTracker(ctx, chainID, tx.Hash().Hex()) - require.False(t, found) + assert.False(t, found) }) t.Run("fail to add proof based tracker with wrong chain id", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) chainID := getValidEthChainID(t) txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() - require.NoError(t, err) + assert.NoError(t, err) setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) msgServer := keeper.NewMsgServerImpl(*k) _, err = msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ @@ -73,9 +73,9 @@ func TestMsgServer_AddToInTxTracker(t *testing.T) { BlockHash: block.Hash().Hex(), TxIndex: txIndex, }) - require.ErrorIs(t, err, observertypes.ErrSupportedChains) + assert.ErrorIs(t, err, observertypes.ErrSupportedChains) _, found := k.GetInTxTracker(ctx, chainID, tx.Hash().Hex()) - require.False(t, found) + assert.False(t, found) }) t.Run("fail normal user submit without proof", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) @@ -92,9 +92,9 @@ func TestMsgServer_AddToInTxTracker(t *testing.T) { BlockHash: "", TxIndex: 0, }) - require.ErrorIs(t, err, observertypes.ErrNotAuthorized) + assert.ErrorIs(t, err, observertypes.ErrNotAuthorized) _, found := k.GetInTxTracker(ctx, chainID, tx_hash) - require.False(t, found) + assert.False(t, found) }) t.Run("admin add tx tracker", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) @@ -113,9 +113,9 @@ func TestMsgServer_AddToInTxTracker(t *testing.T) { BlockHash: "", TxIndex: 0, }) - require.NoError(t, err) + assert.NoError(t, err) _, found := k.GetInTxTracker(ctx, chainID, tx_hash) - require.True(t, found) + assert.True(t, found) }) t.Run("admin submit fake tracker", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) @@ -134,11 +134,11 @@ func TestMsgServer_AddToInTxTracker(t *testing.T) { BlockHash: "", TxIndex: 0, }) - require.NoError(t, err) + assert.NoError(t, err) _, found := k.GetInTxTracker(ctx, chainID, "Malicious TX HASH") - require.True(t, found) + assert.True(t, found) _, found = k.GetInTxTracker(ctx, chainID, tx_hash) - require.False(t, found) + assert.False(t, found) }) } diff --git a/x/crosschain/keeper/msg_server_add_to_outtx_tracker_test.go b/x/crosschain/keeper/msg_server_add_to_outtx_tracker_test.go index 72820fcffc..546650d61a 100644 --- a/x/crosschain/keeper/msg_server_add_to_outtx_tracker_test.go +++ b/x/crosschain/keeper/msg_server_add_to_outtx_tracker_test.go @@ -8,7 +8,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" "github.com/zeta-chain/zetacore/common/ethereum" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" @@ -30,7 +29,7 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { setAdminPolicies(ctx, zk, admin) chainID := getEthereumChainID() txIndex, block, header, headerRLP, _, tx, err := sample.Proof() - require.NoError(t, err) + assert.NoError(t, err) setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) setupTssAndNonceToCctx(k, ctx, chainID, 0) msgServer := keeper.NewMsgServerImpl(*k) @@ -43,9 +42,9 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { TxIndex: 0, Nonce: 0, }) - require.NoError(t, err) + assert.NoError(t, err) _, found := k.GetOutTxTracker(ctx, chainID, 0) - require.True(t, found) + assert.True(t, found) }) t.Run("unable to add tracker admin exceeding maximum allowed length of hashlist without proof", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) @@ -53,7 +52,7 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { setAdminPolicies(ctx, zk, admin) chainID := getEthereumChainID() txIndex, block, header, headerRLP, _, tx, err := sample.Proof() - require.NoError(t, err) + assert.NoError(t, err) setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) setupTssAndNonceToCctx(k, ctx, chainID, 0) k.SetOutTxTracker(ctx, types.OutTxTracker{ @@ -82,17 +81,17 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { TxIndex: 0, Nonce: 0, }) - require.NoError(t, err) + assert.NoError(t, err) tracker, found := k.GetOutTxTracker(ctx, chainID, 0) - require.True(t, found) - require.Equal(t, 2, len(tracker.HashList)) + assert.True(t, found) + assert.Equal(t, 2, len(tracker.HashList)) }) t.Run("fail add proof based tracker with wrong chainID", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) chainID := getEthereumChainID() txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() - require.NoError(t, err) + assert.NoError(t, err) setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) setupTssAndNonceToCctx(k, ctx, chainID, int64(tx.Nonce())) msgServer := keeper.NewMsgServerImpl(*k) @@ -105,16 +104,16 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { TxIndex: txIndex, Nonce: tx.Nonce(), }) - require.ErrorIs(t, err, observertypes.ErrSupportedChains) + assert.ErrorIs(t, err, observertypes.ErrSupportedChains) _, found := k.GetOutTxTracker(ctx, chainID, tx.Nonce()) - require.False(t, found) + assert.False(t, found) }) t.Run("fail add proof based tracker with wrong nonce", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) chainID := getEthereumChainID() txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() - require.NoError(t, err) + assert.NoError(t, err) setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) setupTssAndNonceToCctx(k, ctx, chainID, 1) msgServer := keeper.NewMsgServerImpl(*k) @@ -127,16 +126,16 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { TxIndex: txIndex, Nonce: 1, }) - require.ErrorIs(t, err, types.ErrTxBodyVerificationFail) + assert.ErrorIs(t, err, types.ErrTxBodyVerificationFail) _, found := k.GetOutTxTracker(ctx, chainID, 1) - require.False(t, found) + assert.False(t, found) }) t.Run("fail add proof based tracker with wrong tx_hash", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) chainID := getEthereumChainID() txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() - require.NoError(t, err) + assert.NoError(t, err) setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) setupTssAndNonceToCctx(k, ctx, chainID, int64(tx.Nonce())) msgServer := keeper.NewMsgServerImpl(*k) @@ -149,16 +148,16 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { TxIndex: txIndex, Nonce: tx.Nonce(), }) - require.ErrorIs(t, err, types.ErrTxBodyVerificationFail) + assert.ErrorIs(t, err, types.ErrTxBodyVerificationFail) _, found := k.GetOutTxTracker(ctx, chainID, tx.Nonce()) - require.False(t, found) + assert.False(t, found) }) t.Run("fail proof based tracker with incorrect proof", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) chainID := getEthereumChainID() txIndex, block, header, headerRLP, _, tx, err := sample.Proof() - require.NoError(t, err) + assert.NoError(t, err) setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) setupTssAndNonceToCctx(k, ctx, chainID, int64(tx.Nonce())) msgServer := keeper.NewMsgServerImpl(*k) @@ -171,15 +170,15 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { TxIndex: txIndex, Nonce: tx.Nonce(), }) - require.ErrorIs(t, err, types.ErrProofVerificationFail) + assert.ErrorIs(t, err, types.ErrProofVerificationFail) _, found := k.GetOutTxTracker(ctx, chainID, tx.Nonce()) - require.False(t, found) + assert.False(t, found) }) t.Run("add proof based tracker with correct proof", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) chainID := getEthereumChainID() txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() - require.NoError(t, err) + assert.NoError(t, err) setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) setupTssAndNonceToCctx(k, ctx, chainID, int64(tx.Nonce())) msgServer := keeper.NewMsgServerImpl(*k) @@ -192,15 +191,15 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { TxIndex: txIndex, Nonce: tx.Nonce(), }) - require.NoError(t, err) + assert.NoError(t, err) _, found := k.GetOutTxTracker(ctx, chainID, tx.Nonce()) - require.True(t, found) + assert.True(t, found) }) t.Run("add proven txHash even if length of hashList is already 2", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) chainID := getEthereumChainID() txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() - require.NoError(t, err) + assert.NoError(t, err) setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) setupTssAndNonceToCctx(k, ctx, chainID, int64(tx.Nonce())) k.SetOutTxTracker(ctx, types.OutTxTracker{ @@ -229,20 +228,20 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { TxIndex: txIndex, Nonce: tx.Nonce(), }) - require.NoError(t, err) + assert.NoError(t, err) tracker, found := k.GetOutTxTracker(ctx, chainID, tx.Nonce()) - require.True(t, found) - require.Equal(t, 3, len(tracker.HashList)) + assert.True(t, found) + assert.Equal(t, 3, len(tracker.HashList)) // Proven tracker is prepended to the list - require.True(t, tracker.HashList[0].Proved) - require.False(t, tracker.HashList[1].Proved) - require.False(t, tracker.HashList[2].Proved) + assert.True(t, tracker.HashList[0].Proved) + assert.False(t, tracker.HashList[1].Proved) + assert.False(t, tracker.HashList[2].Proved) }) t.Run("add proof for existing txHash", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) chainID := getEthereumChainID() txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() - require.NoError(t, err) + assert.NoError(t, err) setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) setupTssAndNonceToCctx(k, ctx, chainID, int64(tx.Nonce())) k.SetOutTxTracker(ctx, types.OutTxTracker{ @@ -258,7 +257,7 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { }) tracker, found := k.GetOutTxTracker(ctx, chainID, tx.Nonce()) assert.True(t, found) - require.False(t, tracker.HashList[0].Proved) + assert.False(t, tracker.HashList[0].Proved) msgServer := keeper.NewMsgServerImpl(*k) _, err = msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ Creator: sample.AccAddress(), @@ -269,11 +268,11 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { TxIndex: txIndex, Nonce: tx.Nonce(), }) - require.NoError(t, err) + assert.NoError(t, err) tracker, found = k.GetOutTxTracker(ctx, chainID, tx.Nonce()) - require.True(t, found) - require.Equal(t, 1, len(tracker.HashList)) - require.True(t, tracker.HashList[0].Proved) + assert.True(t, found) + assert.Equal(t, 1, len(tracker.HashList)) + assert.True(t, tracker.HashList[0].Proved) }) } diff --git a/x/crosschain/keeper/msg_server_migrate_tss_funds_test.go b/x/crosschain/keeper/msg_server_migrate_tss_funds_test.go index 4d909abdf0..c8aadf0de4 100644 --- a/x/crosschain/keeper/msg_server_migrate_tss_funds_test.go +++ b/x/crosschain/keeper/msg_server_migrate_tss_funds_test.go @@ -6,7 +6,7 @@ import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/crypto" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/common" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -25,20 +25,20 @@ func TestKeeper_MigrateTSSFundsForChain(t *testing.T) { amount := sdkmath.NewUintFromString("10000000000000000000") indexString, _ := setupTssMigrationParams(zk, k, ctx, *chain, amount, true, true) gp, found := k.GetMedianGasPriceInUint(ctx, chain.ChainId) - require.True(t, found) + assert.True(t, found) _, err := msgServer.MigrateTssFunds(ctx, &crosschaintypes.MsgMigrateTssFunds{ Creator: admin, ChainId: chain.ChainId, Amount: amount, }) - require.NoError(t, err) + assert.NoError(t, err) hash := crypto.Keccak256Hash([]byte(indexString)) index := hash.Hex() cctx, found := k.GetCrossChainTx(ctx, index) - require.True(t, found) + assert.True(t, found) multipliedValue, err := common.MultiplyGasPrice(gp, crosschaintypes.TssMigrationGasMultiplierEVM) - require.NoError(t, err) - require.Equal(t, multipliedValue.String(), cctx.GetCurrentOutTxParam().OutboundTxGasPrice) + assert.NoError(t, err) + assert.Equal(t, multipliedValue.String(), cctx.GetCurrentOutTxParam().OutboundTxGasPrice) }) } @@ -56,14 +56,14 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { ChainId: chain.ChainId, Amount: amount, }) - require.NoError(t, err) + assert.NoError(t, err) hash := crypto.Keccak256Hash([]byte(indexString)) index := hash.Hex() cctx, found := k.GetCrossChainTx(ctx, index) - require.True(t, found) + assert.True(t, found) feeCalculated := sdk.NewUint(cctx.GetCurrentOutTxParam().OutboundTxGasLimit). Mul(sdkmath.NewUintFromString(cctx.GetCurrentOutTxParam().OutboundTxGasPrice)) - require.Equal(t, cctx.GetCurrentOutTxParam().Amount.String(), amount.Sub(feeCalculated).String()) + assert.Equal(t, cctx.GetCurrentOutTxParam().Amount.String(), amount.Sub(feeCalculated).String()) }) t.Run("not enough funds in tss address for migration", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) @@ -78,11 +78,11 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { ChainId: chain.ChainId, Amount: amount, }) - require.ErrorContains(t, err, crosschaintypes.ErrCannotMigrateTssFunds.Error()) + assert.ErrorContains(t, err, crosschaintypes.ErrCannotMigrateTssFunds.Error()) hash := crypto.Keccak256Hash([]byte(indexString)) index := hash.Hex() _, found := k.GetCrossChainTx(ctx, index) - require.False(t, found) + assert.False(t, found) }) t.Run("unable to migrate funds if new TSS is not created ", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) @@ -97,11 +97,11 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { ChainId: chain.ChainId, Amount: amount, }) - require.ErrorContains(t, err, "no new tss address has been generated") + assert.ErrorContains(t, err, "no new tss address has been generated") hash := crypto.Keccak256Hash([]byte(indexString)) index := hash.Hex() _, found := k.GetCrossChainTx(ctx, index) - require.False(t, found) + assert.False(t, found) }) t.Run("unable to migrate funds when nonce low does not match nonce high", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) @@ -122,12 +122,12 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { ChainId: chain.ChainId, Amount: amount, }) - require.ErrorIs(t, err, crosschaintypes.ErrCannotMigrateTssFunds) - require.ErrorContains(t, err, "cannot migrate funds when there are pending nonces") + assert.ErrorIs(t, err, crosschaintypes.ErrCannotMigrateTssFunds) + assert.ErrorContains(t, err, "cannot migrate funds when there are pending nonces") hash := crypto.Keccak256Hash([]byte(indexString)) index := hash.Hex() _, found := k.GetCrossChainTx(ctx, index) - require.False(t, found) + assert.False(t, found) }) t.Run("unable to migrate funds when a pending cctx is presnt in migration info", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) @@ -155,14 +155,14 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { ChainId: chain.ChainId, Amount: amount, }) - require.ErrorIs(t, err, crosschaintypes.ErrCannotMigrateTssFunds) - require.ErrorContains(t, err, "cannot migrate funds while there are pending migrations") + assert.ErrorIs(t, err, crosschaintypes.ErrCannotMigrateTssFunds) + assert.ErrorContains(t, err, "cannot migrate funds while there are pending migrations") hash := crypto.Keccak256Hash([]byte(indexString)) index := hash.Hex() _, found := k.GetCrossChainTx(ctx, index) - require.False(t, found) + assert.False(t, found) _, found = k.GetCrossChainTx(ctx, existingCctx.Index) - require.True(t, found) + assert.True(t, found) }) t.Run("unable to migrate funds if current TSS is not present in TSSHistory and no new TSS has been generated", func(t *testing.T) { @@ -174,7 +174,7 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { amount := sdkmath.NewUintFromString("10000000000000000000") indexString, _ := setupTssMigrationParams(zk, k, ctx, *chain, amount, false, false) currentTss, found := k.GetObserverKeeper().GetTSS(ctx) - require.True(t, found) + assert.True(t, found) newTss := sample.Tss() newTss.FinalizedZetaHeight = currentTss.FinalizedZetaHeight - 10 newTss.KeyGenZetaHeight = currentTss.KeyGenZetaHeight - 10 @@ -184,12 +184,12 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { ChainId: chain.ChainId, Amount: amount, }) - require.ErrorIs(t, err, crosschaintypes.ErrCannotMigrateTssFunds) - require.ErrorContains(t, err, "current tss is the latest") + assert.ErrorIs(t, err, crosschaintypes.ErrCannotMigrateTssFunds) + assert.ErrorContains(t, err, "current tss is the latest") hash := crypto.Keccak256Hash([]byte(indexString)) index := hash.Hex() _, found = k.GetCrossChainTx(ctx, index) - require.False(t, found) + assert.False(t, found) }) } func setupTssMigrationParams( diff --git a/x/crosschain/keeper/msg_server_update_tss_test.go b/x/crosschain/keeper/msg_server_update_tss_test.go index 9d1207d427..6f9ff04e8e 100644 --- a/x/crosschain/keeper/msg_server_update_tss_test.go +++ b/x/crosschain/keeper/msg_server_update_tss_test.go @@ -3,9 +3,8 @@ package keeper_test import ( "testing" - "github.com/stretchr/testify/require" - "github.com/stretchr/testify/assert" + keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/crosschain/keeper" @@ -134,16 +133,16 @@ func TestMsgServer_UpdateTssAddress(t *testing.T) { cctx.CctxStatus.Status = crosschaintypes.CctxStatus_OutboundMined k.SetCrossChainTx(ctx, *cctx) - require.Equal(t, len(k.GetObserverKeeper().GetAllTssFundMigrators(ctx)), 1) + assert.Equal(t, len(k.GetObserverKeeper().GetAllTssFundMigrators(ctx)), 1) _, err := msgServer.UpdateTssAddress(ctx, &crosschaintypes.MsgUpdateTssAddress{ Creator: admin, TssPubkey: tssNew.TssPubkey, }) - require.ErrorContains(t, err, "cannot update tss address not enough migrations have been created and completed") - require.ErrorIs(t, err, crosschaintypes.ErrUnableToUpdateTss) + assert.ErrorContains(t, err, "cannot update tss address not enough migrations have been created and completed") + assert.ErrorIs(t, err, crosschaintypes.ErrUnableToUpdateTss) tss, found := k.GetObserverKeeper().GetTSS(ctx) - require.True(t, found) - require.Equal(t, tssOld, tss) + assert.True(t, found) + assert.Equal(t, tssOld, tss) migrators := k.GetObserverKeeper().GetAllTssFundMigrators(ctx) assert.Equal(t, 1, len(migrators)) }) diff --git a/x/crosschain/keeper/msg_server_vote_inbound_tx.go b/x/crosschain/keeper/msg_server_vote_inbound_tx.go index 57c3e54041..3b4034c485 100644 --- a/x/crosschain/keeper/msg_server_vote_inbound_tx.go +++ b/x/crosschain/keeper/msg_server_vote_inbound_tx.go @@ -32,7 +32,7 @@ import ( // // If the receiver chain is a connected chain, the `FinalizeInbound` method is // called to prepare the CCTX to be processed as an outbound transaction. To -// cover the outbound transaction fee, the required amount of tokens submitted +// cover the outbound transaction fee, the assertd amount of tokens submitted // with the CCTX are swapped using a Uniswap V2 contract instance on ZetaChain // for the ZRC20 of the gas token of the receiver chain. The ZRC20 tokens are // then burned. The nonce is updated. If everything is successful, the CCTX diff --git a/x/crosschain/keeper/msg_server_vote_outbound_tx.go b/x/crosschain/keeper/msg_server_vote_outbound_tx.go index 17319d1f8a..30af53fdcc 100644 --- a/x/crosschain/keeper/msg_server_vote_outbound_tx.go +++ b/x/crosschain/keeper/msg_server_vote_outbound_tx.go @@ -31,7 +31,7 @@ import ( // status. // // If the previous status was `PendingOutbound`, a new revert transaction is -// created. To cover the revert transaction fee, the required amount of tokens +// created. To cover the revert transaction fee, the assertd amount of tokens // submitted with the CCTX are swapped using a Uniswap V2 contract instance on // ZetaChain for the ZRC20 of the gas token of the receiver chain. The ZRC20 // tokens are then diff --git a/x/crosschain/keeper/msg_server_vote_outbound_tx_test.go b/x/crosschain/keeper/msg_server_vote_outbound_tx_test.go index b5ad6ab78d..0f1c15ac17 100644 --- a/x/crosschain/keeper/msg_server_vote_outbound_tx_test.go +++ b/x/crosschain/keeper/msg_server_vote_outbound_tx_test.go @@ -7,7 +7,7 @@ import ( "testing" "cosmossdk.io/math" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" testkeeper "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/crosschain/keeper" @@ -102,10 +102,10 @@ func TestKeeper_FundGasStabilityPoolFromRemainingFees(t *testing.T) { err := k.FundGasStabilityPoolFromRemainingFees(ctx, *outbound, 42) if tc.isError { - require.Error(t, err) + assert.Error(t, err) return } - require.NoError(t, err) + assert.NoError(t, err) fungibleMock.AssertExpectations(t) }) diff --git a/x/crosschain/keeper/msg_server_whitelist_erc20_test.go b/x/crosschain/keeper/msg_server_whitelist_erc20_test.go index 82cd292fb2..324ac6ff02 100644 --- a/x/crosschain/keeper/msg_server_whitelist_erc20_test.go +++ b/x/crosschain/keeper/msg_server_whitelist_erc20_test.go @@ -6,7 +6,7 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ethcommon "github.com/ethereum/go-ethereum/common" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/common" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -45,25 +45,25 @@ func TestKeeper_WhitelistERC20(t *testing.T) { Decimals: 18, GasLimit: 100000, }) - require.NoError(t, err) - require.NotNil(t, res) + assert.NoError(t, err) + assert.NotNil(t, res) zrc20 := res.Zrc20Address cctxIndex := res.CctxIndex // check zrc20 and cctx created assertContractDeployment(t, sdkk.EvmKeeper, ctx, ethcommon.HexToAddress(zrc20)) fc, found := zk.FungibleKeeper.GetForeignCoins(ctx, zrc20) - require.True(t, found) - require.EqualValues(t, "foo", fc.Name) - require.EqualValues(t, erc20Address, fc.Asset) + assert.True(t, found) + assert.EqualValues(t, "foo", fc.Name) + assert.EqualValues(t, erc20Address, fc.Asset) cctx, found := k.GetCrossChainTx(ctx, cctxIndex) - require.True(t, found) - require.EqualValues(t, fmt.Sprintf("%s:%s", common.CmdWhitelistERC20, erc20Address), cctx.RelayedMessage) + assert.True(t, found) + assert.EqualValues(t, fmt.Sprintf("%s:%s", common.CmdWhitelistERC20, erc20Address), cctx.RelayedMessage) // check gas limit is set gasLimit, err := zk.FungibleKeeper.QueryGasLimit(ctx, ethcommon.HexToAddress(zrc20)) - require.NoError(t, err) - require.Equal(t, uint64(100000), gasLimit.Uint64()) + assert.NoError(t, err) + assert.Equal(t, uint64(100000), gasLimit.Uint64()) // Ensure that whitelist a new erc20 create a cctx with a different index res, err = msgServer.WhitelistERC20(ctx, &types.MsgWhitelistERC20{ @@ -75,9 +75,9 @@ func TestKeeper_WhitelistERC20(t *testing.T) { Decimals: 18, GasLimit: 100000, }) - require.NoError(t, err) - require.NotNil(t, res) - require.NotEqual(t, cctxIndex, res.CctxIndex) + assert.NoError(t, err) + assert.NotNil(t, res) + assert.NotEqual(t, cctxIndex, res.CctxIndex) }) t.Run("should fail if not authorized", func(t *testing.T) { @@ -94,7 +94,7 @@ func TestKeeper_WhitelistERC20(t *testing.T) { Decimals: 18, GasLimit: 100000, }) - require.ErrorIs(t, err, sdkerrors.ErrUnauthorized) + assert.ErrorIs(t, err, sdkerrors.ErrUnauthorized) }) t.Run("should fail if invalid erc20 address", func(t *testing.T) { @@ -114,7 +114,7 @@ func TestKeeper_WhitelistERC20(t *testing.T) { Decimals: 18, GasLimit: 100000, }) - require.ErrorIs(t, err, sdkerrors.ErrInvalidAddress) + assert.ErrorIs(t, err, sdkerrors.ErrInvalidAddress) }) t.Run("should fail if foreign coin already exists for the asset", func(t *testing.T) { @@ -141,7 +141,7 @@ func TestKeeper_WhitelistERC20(t *testing.T) { Decimals: 18, GasLimit: 100000, }) - require.ErrorIs(t, err, fungibletypes.ErrForeignCoinAlreadyExist) + assert.ErrorIs(t, err, fungibletypes.ErrForeignCoinAlreadyExist) }) t.Run("should fail if no tss set", func(t *testing.T) { @@ -163,7 +163,7 @@ func TestKeeper_WhitelistERC20(t *testing.T) { Decimals: 18, GasLimit: 100000, }) - require.ErrorIs(t, err, types.ErrCannotFindTSSKeys) + assert.ErrorIs(t, err, types.ErrCannotFindTSSKeys) }) t.Run("should fail if nox valid chain ID", func(t *testing.T) { @@ -185,6 +185,6 @@ func TestKeeper_WhitelistERC20(t *testing.T) { Decimals: 18, GasLimit: 100000, }) - require.ErrorIs(t, err, types.ErrInvalidChainID) + assert.ErrorIs(t, err, types.ErrInvalidChainID) }) } diff --git a/x/crosschain/keeper/out_tx_tracker_test.go b/x/crosschain/keeper/out_tx_tracker_test.go index 4b849b4c3d..5644d30db4 100644 --- a/x/crosschain/keeper/out_tx_tracker_test.go +++ b/x/crosschain/keeper/out_tx_tracker_test.go @@ -5,7 +5,7 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/nullify" "github.com/zeta-chain/zetacore/x/crosschain/keeper" @@ -33,8 +33,8 @@ func TestOutTxTrackerGet(t *testing.T) { item.ChainId, item.Nonce, ) - require.True(t, found) - require.Equal(t, + assert.True(t, found) + assert.Equal(t, nullify.Fill(&item), nullify.Fill(&rst), ) @@ -52,14 +52,14 @@ func TestOutTxTrackerRemove(t *testing.T) { item.ChainId, item.Nonce, ) - require.False(t, found) + assert.False(t, found) } } func TestOutTxTrackerGetAll(t *testing.T) { keeper, ctx, _, _ := keepertest.CrosschainKeeper(t) items := createNOutTxTracker(keeper, ctx, 10) - require.ElementsMatch(t, + assert.ElementsMatch(t, nullify.Fill(items), nullify.Fill(keeper.GetAllOutTxTracker(ctx)), ) diff --git a/x/crosschain/keeper/utils_test.go b/x/crosschain/keeper/utils_test.go index 83f37b2799..088d10e604 100644 --- a/x/crosschain/keeper/utils_test.go +++ b/x/crosschain/keeper/utils_test.go @@ -12,7 +12,7 @@ import ( bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" "github.com/ethereum/go-ethereum/common" evmkeeper "github.com/evmos/ethermint/x/evm/keeper" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/protocol-contracts/pkg/uniswap/v2-periphery/contracts/uniswapv2router02.sol" "github.com/zeta-chain/zetacore/cmd/zetacored/config" zetacommon "github.com/zeta-chain/zetacore/common" @@ -40,7 +40,7 @@ func getValidEthChainIDWithIndex(t *testing.T, index int) int64 { case 1: return zetacommon.GoerliChain().ChainId default: - require.Fail(t, "invalid index") + assert.Fail(t, "invalid index") } return 0 } @@ -48,10 +48,10 @@ func getValidEthChainIDWithIndex(t *testing.T, index int) int64 { // assert that a contract has been deployed by checking stored code is non-empty. func assertContractDeployment(t *testing.T, k *evmkeeper.Keeper, ctx sdk.Context, contractAddress common.Address) { acc := k.GetAccount(ctx, contractAddress) - require.NotNil(t, acc) + assert.NotNil(t, acc) code := k.GetCode(ctx, common.BytesToHash(acc.CodeHash)) - require.NotEmpty(t, code) + assert.NotEmpty(t, code) } // deploySystemContracts deploys the system contracts and returns their addresses. @@ -64,28 +64,28 @@ func deploySystemContracts( var err error wzeta, err = k.DeployWZETA(ctx) - require.NoError(t, err) - require.NotEmpty(t, wzeta) + assert.NoError(t, err) + assert.NotEmpty(t, wzeta) assertContractDeployment(t, evmk, ctx, wzeta) uniswapV2Factory, err = k.DeployUniswapV2Factory(ctx) - require.NoError(t, err) - require.NotEmpty(t, uniswapV2Factory) + assert.NoError(t, err) + assert.NotEmpty(t, uniswapV2Factory) assertContractDeployment(t, evmk, ctx, uniswapV2Factory) uniswapV2Router, err = k.DeployUniswapV2Router02(ctx, uniswapV2Factory, wzeta) - require.NoError(t, err) - require.NotEmpty(t, uniswapV2Router) + assert.NoError(t, err) + assert.NotEmpty(t, uniswapV2Router) assertContractDeployment(t, evmk, ctx, uniswapV2Router) connector, err = k.DeployConnectorZEVM(ctx, wzeta) - require.NoError(t, err) - require.NotEmpty(t, connector) + assert.NoError(t, err) + assert.NotEmpty(t, connector) assertContractDeployment(t, evmk, ctx, connector) systemContract, err = k.DeploySystemContract(ctx, wzeta, uniswapV2Factory, uniswapV2Router) - require.NoError(t, err) - require.NotEmpty(t, systemContract) + assert.NoError(t, err) + assert.NotEmpty(t, systemContract) assertContractDeployment(t, evmk, ctx, systemContract) return @@ -109,7 +109,7 @@ func setupGasCoin( 8, nil, ) - require.NoError(t, err) + assert.NoError(t, err) assertContractDeployment(t, evmk, ctx, addr) return addr } @@ -135,7 +135,7 @@ func deployZRC20( assetAddress, big.NewInt(21_000), ) - require.NoError(t, err) + assert.NoError(t, err) assertContractDeployment(t, evmk, ctx, addr) return addr } @@ -149,22 +149,22 @@ func setupZRC20Pool( zrc20Addr common.Address, ) { routerAddress, err := k.GetUniswapV2Router02Address(ctx) - require.NoError(t, err) + assert.NoError(t, err) routerABI, err := uniswapv2router02.UniswapV2Router02MetaData.GetAbi() - require.NoError(t, err) + assert.NoError(t, err) // enough for the small numbers used in test liquidityAmount := big.NewInt(1e17) // mint some zrc20 and zeta _, err = k.DepositZRC20(ctx, zrc20Addr, types.ModuleAddressEVM, liquidityAmount) - require.NoError(t, err) + assert.NoError(t, err) err = bankKeeper.MintCoins( ctx, types.ModuleName, sdk.NewCoins(sdk.NewCoin(config.BaseDenom, sdk.NewIntFromBigInt(liquidityAmount))), ) - require.NoError(t, err) + assert.NoError(t, err) // approve the router to spend the zeta err = k.CallZRC20Approve( @@ -175,7 +175,7 @@ func setupZRC20Pool( liquidityAmount, false, ) - require.NoError(t, err) + assert.NoError(t, err) // add the liquidity //function addLiquidityETH( @@ -203,7 +203,7 @@ func setupZRC20Pool( types.ModuleAddressEVM, liquidityAmount, ) - require.NoError(t, err) + assert.NoError(t, err) } // setAdminPolicies sets the admin policies for the observer module with group 1 and 2 diff --git a/x/crosschain/keeper/zeta_accounting_test.go b/x/crosschain/keeper/zeta_accounting_test.go index 1d5e1f7921..a20ada338c 100644 --- a/x/crosschain/keeper/zeta_accounting_test.go +++ b/x/crosschain/keeper/zeta_accounting_test.go @@ -5,7 +5,7 @@ import ( "testing" sdkmath "cosmossdk.io/math" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/x/crosschain/types" ) @@ -19,20 +19,20 @@ func TestKeeper_AddZetaAccounting(t *testing.T) { AbortedZetaAmount: originalAmount, }) val, found := k.GetZetaAccounting(ctx) - require.True(t, found) - require.Equal(t, originalAmount, val.AbortedZetaAmount) + assert.True(t, found) + assert.Equal(t, originalAmount, val.AbortedZetaAmount) addAmount := sdkmath.NewUint(rand.Uint64()) k.AddZetaAbortedAmount(ctx, addAmount) val, found = k.GetZetaAccounting(ctx) - require.True(t, found) - require.Equal(t, originalAmount.Add(addAmount), val.AbortedZetaAmount) + assert.True(t, found) + assert.Equal(t, originalAmount.Add(addAmount), val.AbortedZetaAmount) }) t.Run("cant find aborted amount", func(t *testing.T) { k, ctx, _, _ := keepertest.CrosschainKeeper(t) val, found := k.GetZetaAccounting(ctx) - require.False(t, found) - require.Equal(t, types.ZetaAccounting{}, val) + assert.False(t, found) + assert.Equal(t, types.ZetaAccounting{}, val) }) t.Run("add very high zeta amount", func(t *testing.T) { @@ -42,8 +42,8 @@ func TestKeeper_AddZetaAccounting(t *testing.T) { AbortedZetaAmount: highAmount, }) val, found := k.GetZetaAccounting(ctx) - require.True(t, found) - require.Equal(t, highAmount, val.AbortedZetaAmount) + assert.True(t, found) + assert.Equal(t, highAmount, val.AbortedZetaAmount) }) } diff --git a/x/crosschain/migrations/v4/migrate_test.go b/x/crosschain/migrations/v4/migrate_test.go index 5ff2f9ee54..98c005c4c8 100644 --- a/x/crosschain/migrations/v4/migrate_test.go +++ b/x/crosschain/migrations/v4/migrate_test.go @@ -10,7 +10,6 @@ import ( "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -148,13 +147,13 @@ func TestSetBitcoinFinalizedInbound(t *testing.T) { v4.SetBitcoinFinalizedInbound(ctx, k) // check finalized inbound - require.False(t, k.IsFinalizedInbound(ctx, "0xaaa", common.GoerliChain().ChainId, 0)) - require.False(t, k.IsFinalizedInbound(ctx, "0xbbb", common.EthChain().ChainId, 0)) - require.False(t, k.IsFinalizedInbound(ctx, "0xccc", common.MumbaiChain().ChainId, 0)) - require.True(t, k.IsFinalizedInbound(ctx, "0x111", common.BtcMainnetChain().ChainId, 0)) - require.True(t, k.IsFinalizedInbound(ctx, "0x222", common.BtcTestNetChain().ChainId, 0)) - require.True(t, k.IsFinalizedInbound(ctx, "0x333", common.BtcTestNetChain().ChainId, 0)) - require.True(t, k.IsFinalizedInbound(ctx, "0x444", common.BtcRegtestChain().ChainId, 0)) + assert.False(t, k.IsFinalizedInbound(ctx, "0xaaa", common.GoerliChain().ChainId, 0)) + assert.False(t, k.IsFinalizedInbound(ctx, "0xbbb", common.EthChain().ChainId, 0)) + assert.False(t, k.IsFinalizedInbound(ctx, "0xccc", common.MumbaiChain().ChainId, 0)) + assert.True(t, k.IsFinalizedInbound(ctx, "0x111", common.BtcMainnetChain().ChainId, 0)) + assert.True(t, k.IsFinalizedInbound(ctx, "0x222", common.BtcTestNetChain().ChainId, 0)) + assert.True(t, k.IsFinalizedInbound(ctx, "0x333", common.BtcTestNetChain().ChainId, 0)) + assert.True(t, k.IsFinalizedInbound(ctx, "0x444", common.BtcRegtestChain().ChainId, 0)) }) } diff --git a/x/crosschain/types/cctx_utils_test.go b/x/crosschain/types/cctx_utils_test.go index 381ef47f6c..6c8be1561d 100644 --- a/x/crosschain/types/cctx_utils_test.go +++ b/x/crosschain/types/cctx_utils_test.go @@ -4,7 +4,7 @@ import ( "math/rand" "testing" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/crosschain/types" ) @@ -14,13 +14,13 @@ func TestCrossChainTx_GetCurrentOutTxParam(t *testing.T) { cctx := sample.CrossChainTx(t, "foo") cctx.OutboundTxParams = []*types.OutboundTxParams{} - require.Equal(t, &types.OutboundTxParams{}, cctx.GetCurrentOutTxParam()) + assert.Equal(t, &types.OutboundTxParams{}, cctx.GetCurrentOutTxParam()) cctx.OutboundTxParams = []*types.OutboundTxParams{sample.OutboundTxParams(r)} - require.Equal(t, cctx.OutboundTxParams[0], cctx.GetCurrentOutTxParam()) + assert.Equal(t, cctx.OutboundTxParams[0], cctx.GetCurrentOutTxParam()) cctx.OutboundTxParams = []*types.OutboundTxParams{sample.OutboundTxParams(r), sample.OutboundTxParams(r)} - require.Equal(t, cctx.OutboundTxParams[1], cctx.GetCurrentOutTxParam()) + assert.Equal(t, cctx.OutboundTxParams[1], cctx.GetCurrentOutTxParam()) } func TestCrossChainTx_IsCurrentOutTxRevert(t *testing.T) { @@ -28,13 +28,13 @@ func TestCrossChainTx_IsCurrentOutTxRevert(t *testing.T) { cctx := sample.CrossChainTx(t, "foo") cctx.OutboundTxParams = []*types.OutboundTxParams{} - require.False(t, cctx.IsCurrentOutTxRevert()) + assert.False(t, cctx.IsCurrentOutTxRevert()) cctx.OutboundTxParams = []*types.OutboundTxParams{sample.OutboundTxParams(r)} - require.False(t, cctx.IsCurrentOutTxRevert()) + assert.False(t, cctx.IsCurrentOutTxRevert()) cctx.OutboundTxParams = []*types.OutboundTxParams{sample.OutboundTxParams(r), sample.OutboundTxParams(r)} - require.True(t, cctx.IsCurrentOutTxRevert()) + assert.True(t, cctx.IsCurrentOutTxRevert()) } func TestCrossChainTx_OriginalDestinationChainID(t *testing.T) { @@ -42,13 +42,13 @@ func TestCrossChainTx_OriginalDestinationChainID(t *testing.T) { cctx := sample.CrossChainTx(t, "foo") cctx.OutboundTxParams = []*types.OutboundTxParams{} - require.Equal(t, int64(-1), cctx.OriginalDestinationChainID()) + assert.Equal(t, int64(-1), cctx.OriginalDestinationChainID()) cctx.OutboundTxParams = []*types.OutboundTxParams{sample.OutboundTxParams(r)} - require.Equal(t, cctx.OutboundTxParams[0].ReceiverChainId, cctx.OriginalDestinationChainID()) + assert.Equal(t, cctx.OutboundTxParams[0].ReceiverChainId, cctx.OriginalDestinationChainID()) cctx.OutboundTxParams = []*types.OutboundTxParams{sample.OutboundTxParams(r), sample.OutboundTxParams(r)} - require.Equal(t, cctx.OutboundTxParams[0].ReceiverChainId, cctx.OriginalDestinationChainID()) + assert.Equal(t, cctx.OutboundTxParams[0].ReceiverChainId, cctx.OriginalDestinationChainID()) } func TestOutboundTxParams_GetGasPrice(t *testing.T) { @@ -58,10 +58,10 @@ func TestOutboundTxParams_GetGasPrice(t *testing.T) { outTxParams.OutboundTxGasPrice = "42" gasPrice, err := outTxParams.GetGasPrice() - require.NoError(t, err) - require.EqualValues(t, uint64(42), gasPrice) + assert.NoError(t, err) + assert.EqualValues(t, uint64(42), gasPrice) outTxParams.OutboundTxGasPrice = "invalid" _, err = outTxParams.GetGasPrice() - require.Error(t, err) + assert.Error(t, err) } diff --git a/x/crosschain/types/genesis_test.go b/x/crosschain/types/genesis_test.go index 2b8b5eb80f..9fe7a827ea 100644 --- a/x/crosschain/types/genesis_test.go +++ b/x/crosschain/types/genesis_test.go @@ -3,7 +3,7 @@ package types_test import ( "testing" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/x/crosschain/types" ) @@ -82,9 +82,9 @@ func TestGenesisState_Validate(t *testing.T) { t.Run(tc.desc, func(t *testing.T) { err := tc.genState.Validate() if tc.valid { - require.NoError(t, err) + assert.NoError(t, err) } else { - require.Error(t, err) + assert.Error(t, err) } }) } diff --git a/x/crosschain/types/message_abort_stuck_cctx_test.go b/x/crosschain/types/message_abort_stuck_cctx_test.go index 40bdcf4794..02eb7c50fd 100644 --- a/x/crosschain/types/message_abort_stuck_cctx_test.go +++ b/x/crosschain/types/message_abort_stuck_cctx_test.go @@ -4,7 +4,7 @@ import ( "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/crosschain/types" ) @@ -36,10 +36,10 @@ func TestMsgAbortStuckCCTX_ValidateBasic(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - require.ErrorIs(t, err, tt.err) + assert.ErrorIs(t, err, tt.err) return } - require.NoError(t, err) + assert.NoError(t, err) }) } } diff --git a/x/crosschain/types/message_add_to_in_tx_tracker_test.go b/x/crosschain/types/message_add_to_in_tx_tracker_test.go index c05272224f..22d7ff08e9 100644 --- a/x/crosschain/types/message_add_to_in_tx_tracker_test.go +++ b/x/crosschain/types/message_add_to_in_tx_tracker_test.go @@ -5,7 +5,7 @@ import ( errorsmod "cosmossdk.io/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/common" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/crosschain/types" @@ -52,10 +52,10 @@ func TestMsgAddToInTxTracker_ValidateBasic(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - require.ErrorIs(t, err, tt.err) + assert.ErrorIs(t, err, tt.err) return } - require.NoError(t, err) + assert.NoError(t, err) }) } } diff --git a/x/crosschain/types/message_add_to_out_tx_tracker_test.go b/x/crosschain/types/message_add_to_out_tx_tracker_test.go index 8a06041989..8caa666b53 100644 --- a/x/crosschain/types/message_add_to_out_tx_tracker_test.go +++ b/x/crosschain/types/message_add_to_out_tx_tracker_test.go @@ -4,7 +4,7 @@ import ( "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/crosschain/types" ) @@ -32,10 +32,10 @@ func TestMsgAddToWatchList_ValidateBasic(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - require.ErrorIs(t, err, tt.err) + assert.ErrorIs(t, err, tt.err) return } - require.NoError(t, err) + assert.NoError(t, err) }) } } diff --git a/x/crosschain/types/message_migrate_tss_funds_test.go b/x/crosschain/types/message_migrate_tss_funds_test.go index a03a4e9ef4..1bc7389651 100644 --- a/x/crosschain/types/message_migrate_tss_funds_test.go +++ b/x/crosschain/types/message_migrate_tss_funds_test.go @@ -4,7 +4,7 @@ import ( "testing" sdkmath "cosmossdk.io/math" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/common" "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/x/crosschain/types" @@ -49,10 +49,10 @@ func TestNewMsgMigrateTssFunds(t *testing.T) { keeper.SetConfig(false) err := tt.msg.ValidateBasic() if tt.error { - require.Error(t, err) + assert.Error(t, err) return } else { - require.NoError(t, err) + assert.NoError(t, err) } }) } diff --git a/x/crosschain/types/message_update_tss_address_test.go b/x/crosschain/types/message_update_tss_address_test.go index ae2bcb25a4..ede82f094c 100644 --- a/x/crosschain/types/message_update_tss_address_test.go +++ b/x/crosschain/types/message_update_tss_address_test.go @@ -3,7 +3,7 @@ package types_test import ( "testing" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/testutil/keeper" crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types" ) @@ -45,10 +45,10 @@ func TestMessageUpdateTssAddress_ValidateBasic(t *testing.T) { keeper.SetConfig(false) err := tt.msg.ValidateBasic() if tt.error { - require.Error(t, err) + assert.Error(t, err) return } else { - require.NoError(t, err) + assert.NoError(t, err) } }) } diff --git a/x/crosschain/types/message_vote_on_observed_inbound_tx_test.go b/x/crosschain/types/message_vote_on_observed_inbound_tx_test.go index 777fb6f244..29704a9101 100644 --- a/x/crosschain/types/message_vote_on_observed_inbound_tx_test.go +++ b/x/crosschain/types/message_vote_on_observed_inbound_tx_test.go @@ -7,7 +7,7 @@ import ( "cosmossdk.io/math" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/common" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/crosschain/types" @@ -125,10 +125,10 @@ func TestMsgVoteOnObservedInboundTx_ValidateBasic(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - require.ErrorIs(t, err, tt.err) + assert.ErrorIs(t, err, tt.err) return } - require.NoError(t, err) + assert.NoError(t, err) }) } } @@ -153,89 +153,89 @@ func TestMsgVoteOnObservedInboundTx_Digest(t *testing.T) { EventIndex: 42, } hash := msg.Digest() - require.NotEmpty(t, hash, "hash should not be empty") + assert.NotEmpty(t, hash, "hash should not be empty") // creator not used msg2 := msg msg2.Creator = sample.AccAddress() hash2 := msg2.Digest() - require.Equal(t, hash, hash2, "creator should not change hash") + assert.Equal(t, hash, hash2, "creator should not change hash") // in block height not used msg2 = msg msg2.InBlockHeight = 43 hash2 = msg2.Digest() - require.Equal(t, hash, hash2, "in block height should not change hash") + assert.Equal(t, hash, hash2, "in block height should not change hash") // sender used msg2 = msg msg2.Sender = sample.AccAddress() hash2 = msg2.Digest() - require.NotEqual(t, hash, hash2, "sender should change hash") + assert.NotEqual(t, hash, hash2, "sender should change hash") // sender chain ID used msg2 = msg msg2.SenderChainId = 43 hash2 = msg2.Digest() - require.NotEqual(t, hash, hash2, "sender chain ID should change hash") + assert.NotEqual(t, hash, hash2, "sender chain ID should change hash") // tx origin used msg2 = msg msg2.TxOrigin = sample.StringRandom(r, 32) hash2 = msg2.Digest() - require.NotEqual(t, hash, hash2, "tx origin should change hash") + assert.NotEqual(t, hash, hash2, "tx origin should change hash") // receiver used msg2 = msg msg2.Receiver = sample.StringRandom(r, 32) hash2 = msg2.Digest() - require.NotEqual(t, hash, hash2, "receiver should change hash") + assert.NotEqual(t, hash, hash2, "receiver should change hash") // receiver chain ID used msg2 = msg msg2.ReceiverChain = 43 hash2 = msg2.Digest() - require.NotEqual(t, hash, hash2, "receiver chain ID should change hash") + assert.NotEqual(t, hash, hash2, "receiver chain ID should change hash") // amount used msg2 = msg msg2.Amount = math.NewUint(43) hash2 = msg2.Digest() - require.NotEqual(t, hash, hash2, "amount should change hash") + assert.NotEqual(t, hash, hash2, "amount should change hash") // message used msg2 = msg msg2.Message = sample.StringRandom(r, 32) hash2 = msg2.Digest() - require.NotEqual(t, hash, hash2, "message should change hash") + assert.NotEqual(t, hash, hash2, "message should change hash") // in tx hash used msg2 = msg msg2.InTxHash = sample.StringRandom(r, 32) hash2 = msg2.Digest() - require.NotEqual(t, hash, hash2, "in tx hash should change hash") + assert.NotEqual(t, hash, hash2, "in tx hash should change hash") // gas limit used msg2 = msg msg2.GasLimit = 43 hash2 = msg2.Digest() - require.NotEqual(t, hash, hash2, "gas limit should change hash") + assert.NotEqual(t, hash, hash2, "gas limit should change hash") // coin type used msg2 = msg msg2.CoinType = common.CoinType_ERC20 hash2 = msg2.Digest() - require.NotEqual(t, hash, hash2, "coin type should change hash") + assert.NotEqual(t, hash, hash2, "coin type should change hash") // asset used msg2 = msg msg2.Asset = sample.StringRandom(r, 32) hash2 = msg2.Digest() - require.NotEqual(t, hash, hash2, "asset should change hash") + assert.NotEqual(t, hash, hash2, "asset should change hash") // event index used msg2 = msg msg2.EventIndex = 43 hash2 = msg2.Digest() - require.NotEqual(t, hash, hash2, "event index should change hash") + assert.NotEqual(t, hash, hash2, "event index should change hash") } diff --git a/x/crosschain/types/message_vote_on_observed_outbound_tx_test.go b/x/crosschain/types/message_vote_on_observed_outbound_tx_test.go index cce6a29c3c..fda1a04d1d 100644 --- a/x/crosschain/types/message_vote_on_observed_outbound_tx_test.go +++ b/x/crosschain/types/message_vote_on_observed_outbound_tx_test.go @@ -6,7 +6,7 @@ import ( "cosmossdk.io/math" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/common" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/crosschain/types" @@ -91,10 +91,10 @@ func TestMsgVoteOnObservedOutboundTx_ValidateBasic(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - require.ErrorIs(t, err, tt.err) + assert.ErrorIs(t, err, tt.err) return } - require.NoError(t, err) + assert.NoError(t, err) }) } } @@ -117,77 +117,77 @@ func TestMsgVoteOnObservedOutboundTx_Digest(t *testing.T) { CoinType: common.CoinType_Zeta, } hash := msg.Digest() - require.NotEmpty(t, hash, "hash should not be empty") + assert.NotEmpty(t, hash, "hash should not be empty") // creator not used msg2 := msg msg2.Creator = sample.AccAddress() hash2 := msg2.Digest() - require.Equal(t, hash, hash2, "creator should not change hash") + assert.Equal(t, hash, hash2, "creator should not change hash") // status not used msg2 = msg msg2.Status = common.ReceiveStatus_Failed hash2 = msg2.Digest() - require.Equal(t, hash, hash2, "status should not change hash") + assert.Equal(t, hash, hash2, "status should not change hash") // cctx hash used msg2 = msg msg2.CctxHash = sample.StringRandom(r, 32) hash2 = msg2.Digest() - require.NotEqual(t, hash, hash2, "cctx hash should change hash") + assert.NotEqual(t, hash, hash2, "cctx hash should change hash") // observed outbound tx hash used msg2 = msg msg2.ObservedOutTxHash = sample.StringRandom(r, 32) hash2 = msg2.Digest() - require.NotEqual(t, hash, hash2, "observed outbound tx hash should change hash") + assert.NotEqual(t, hash, hash2, "observed outbound tx hash should change hash") // observed outbound tx block height used msg2 = msg msg2.ObservedOutTxBlockHeight = 43 hash2 = msg2.Digest() - require.NotEqual(t, hash, hash2, "observed outbound tx block height should change hash") + assert.NotEqual(t, hash, hash2, "observed outbound tx block height should change hash") // observed outbound tx gas used used msg2 = msg msg2.ObservedOutTxGasUsed = 43 hash2 = msg2.Digest() - require.NotEqual(t, hash, hash2, "observed outbound tx gas used should change hash") + assert.NotEqual(t, hash, hash2, "observed outbound tx gas used should change hash") // observed outbound tx effective gas price used msg2 = msg msg2.ObservedOutTxEffectiveGasPrice = math.NewInt(43) hash2 = msg2.Digest() - require.NotEqual(t, hash, hash2, "observed outbound tx effective gas price should change hash") + assert.NotEqual(t, hash, hash2, "observed outbound tx effective gas price should change hash") // observed outbound tx effective gas limit used msg2 = msg msg2.ObservedOutTxEffectiveGasLimit = 43 hash2 = msg2.Digest() - require.NotEqual(t, hash, hash2, "observed outbound tx effective gas limit should change hash") + assert.NotEqual(t, hash, hash2, "observed outbound tx effective gas limit should change hash") // zeta minted used msg2 = msg msg2.ValueReceived = math.NewUint(43) hash2 = msg2.Digest() - require.NotEqual(t, hash, hash2, "zeta minted should change hash") + assert.NotEqual(t, hash, hash2, "zeta minted should change hash") // out tx chain used msg2 = msg msg2.OutTxChain = 43 hash2 = msg2.Digest() - require.NotEqual(t, hash, hash2, "out tx chain should change hash") + assert.NotEqual(t, hash, hash2, "out tx chain should change hash") // out tx tss nonce used msg2 = msg msg2.OutTxTssNonce = 43 hash2 = msg2.Digest() - require.NotEqual(t, hash, hash2, "out tx tss nonce should change hash") + assert.NotEqual(t, hash, hash2, "out tx tss nonce should change hash") // coin type used msg2 = msg msg2.CoinType = common.CoinType_ERC20 hash2 = msg2.Digest() - require.NotEqual(t, hash, hash2, "coin type should change hash") + assert.NotEqual(t, hash, hash2, "coin type should change hash") } diff --git a/x/emissions/genesis_test.go b/x/emissions/genesis_test.go index cae3948ce1..7ad8ec6aa6 100644 --- a/x/emissions/genesis_test.go +++ b/x/emissions/genesis_test.go @@ -3,7 +3,7 @@ package emissions_test import ( "testing" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/nullify" "github.com/zeta-chain/zetacore/testutil/sample" @@ -25,10 +25,10 @@ func TestGenesis(t *testing.T) { k, ctx := keepertest.EmissionsKeeper(t) emissions.InitGenesis(ctx, *k, genesisState) got := emissions.ExportGenesis(ctx, *k) - require.NotNil(t, got) + assert.NotNil(t, got) // Compare genesis after init and export nullify.Fill(&genesisState) nullify.Fill(got) - require.Equal(t, genesisState, *got) + assert.Equal(t, genesisState, *got) } diff --git a/x/emissions/types/genesis_test.go b/x/emissions/types/genesis_test.go index 6e0f27b4bc..46853a4e94 100644 --- a/x/emissions/types/genesis_test.go +++ b/x/emissions/types/genesis_test.go @@ -3,7 +3,7 @@ package types_test import ( "testing" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/x/emissions/types" ) @@ -27,9 +27,9 @@ func TestGenesisState_Validate(t *testing.T) { t.Run(tc.desc, func(t *testing.T) { err := tc.genState.Validate() if tc.valid { - require.NoError(t, err) + assert.NoError(t, err) } else { - require.Error(t, err) + assert.Error(t, err) } }) } diff --git a/x/fungible/client/cli/query_foreign_coins_test.go b/x/fungible/client/cli/query_foreign_coins_test.go index b2e2602f7c..e661ee62c7 100644 --- a/x/fungible/client/cli/query_foreign_coins_test.go +++ b/x/fungible/client/cli/query_foreign_coins_test.go @@ -8,7 +8,7 @@ package cli_test // // "github.com/cosmos/cosmos-sdk/client/flags" // clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" -// "github.com/stretchr/testify/require" +// "github.com/stretchr/testify/assert" // tmcli "github.com/tendermint/tendermint/libs/cli" // "google.golang.org/grpc/codes" // "google.golang.org/grpc/status" @@ -26,7 +26,7 @@ package cli_test // t.Helper() // cfg := network.DefaultConfig() // state := types.GenesisState{} -// require.NoError(t, cfg.Codec.UnmarshalJSON(cfg.GenesisState[types.ModuleName], &state)) +// assert.NoError(t, cfg.Codec.UnmarshalJSON(cfg.GenesisState[types.ModuleName], &state)) // // for i := 0; i < n; i++ { // foreignCoins := types.ForeignCoins{ @@ -36,7 +36,7 @@ package cli_test // state.ForeignCoinsList = append(state.ForeignCoinsList, foreignCoins) // } // buf, err := cfg.Codec.MarshalJSON(&state) -// require.NoError(t, err) +// assert.NoError(t, err) // cfg.GenesisState[types.ModuleName] = buf // return network.New(t, cfg), state.ForeignCoinsList //} @@ -79,14 +79,14 @@ package cli_test // out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdShowForeignCoins(), args) // if tc.err != nil { // stat, ok := status.FromError(tc.err) -// require.True(t, ok) -// require.ErrorIs(t, stat.Err(), tc.err) +// assert.True(t, ok) +// assert.ErrorIs(t, stat.Err(), tc.err) // } else { -// require.NoError(t, err) +// assert.NoError(t, err) // var resp types.QueryGetForeignCoinsResponse -// require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) -// require.NotNil(t, resp.ForeignCoins) -// require.Equal(t, +// assert.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) +// assert.NotNil(t, resp.ForeignCoins) +// assert.Equal(t, // nullify.Fill(&tc.obj), // nullify.Fill(&resp.ForeignCoins), // ) @@ -119,11 +119,11 @@ package cli_test // for i := 0; i < len(objs); i += step { // args := request(nil, uint64(i), uint64(step), false) // out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdListForeignCoins(), args) -// require.NoError(t, err) +// assert.NoError(t, err) // var resp types.QueryAllForeignCoinsResponse -// require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) -// require.LessOrEqual(t, len(resp.ForeignCoins), step) -// require.Subset(t, +// assert.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) +// assert.LessOrEqual(t, len(resp.ForeignCoins), step) +// assert.Subset(t, // nullify.Fill(objs), // nullify.Fill(resp.ForeignCoins), // ) @@ -135,11 +135,11 @@ package cli_test // for i := 0; i < len(objs); i += step { // args := request(next, 0, uint64(step), false) // out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdListForeignCoins(), args) -// require.NoError(t, err) +// assert.NoError(t, err) // var resp types.QueryAllForeignCoinsResponse -// require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) -// require.LessOrEqual(t, len(resp.ForeignCoins), step) -// require.Subset(t, +// assert.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) +// assert.LessOrEqual(t, len(resp.ForeignCoins), step) +// assert.Subset(t, // nullify.Fill(objs), // nullify.Fill(resp.ForeignCoins), // ) @@ -149,12 +149,12 @@ package cli_test // t.Run("Total", func(t *testing.T) { // args := request(nil, 0, uint64(len(objs)), true) // out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdListForeignCoins(), args) -// require.NoError(t, err) +// assert.NoError(t, err) // var resp types.QueryAllForeignCoinsResponse -// require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) -// require.NoError(t, err) -// require.Equal(t, len(objs), int(resp.Pagination.Total)) -// require.ElementsMatch(t, +// assert.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) +// assert.NoError(t, err) +// assert.Equal(t, len(objs), int(resp.Pagination.Total)) +// assert.ElementsMatch(t, // nullify.Fill(objs), // nullify.Fill(resp.ForeignCoins), // ) diff --git a/x/fungible/genesis_test.go b/x/fungible/genesis_test.go index 119e862a18..2b72fb443f 100644 --- a/x/fungible/genesis_test.go +++ b/x/fungible/genesis_test.go @@ -3,7 +3,7 @@ package fungible_test import ( "testing" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/nullify" "github.com/zeta-chain/zetacore/testutil/sample" @@ -26,10 +26,10 @@ func TestGenesis(t *testing.T) { k, ctx, _, _ := keepertest.FungibleKeeper(t) fungible.InitGenesis(ctx, *k, genesisState) got := fungible.ExportGenesis(ctx, *k) - require.NotNil(t, got) + assert.NotNil(t, got) // Compare genesis after init and export nullify.Fill(&genesisState) nullify.Fill(got) - require.Equal(t, genesisState, *got) + assert.Equal(t, genesisState, *got) } diff --git a/x/fungible/keeper/deposits_test.go b/x/fungible/keeper/deposits_test.go index 4131a1e00d..d352851be3 100644 --- a/x/fungible/keeper/deposits_test.go +++ b/x/fungible/keeper/deposits_test.go @@ -6,7 +6,7 @@ import ( "cosmossdk.io/math" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/common" "github.com/zeta-chain/zetacore/testutil/contracts" testkeeper "github.com/zeta-chain/zetacore/testutil/keeper" @@ -40,12 +40,12 @@ func TestKeeper_ZRC20DepositAndCallContract(t *testing.T) { common.CoinType_Gas, sample.EthAddress().String(), ) - require.NoError(t, err) - require.False(t, contractCall) + assert.NoError(t, err) + assert.False(t, contractCall) balance, err := k.BalanceOfZRC4(ctx, zrc20, to) - require.NoError(t, err) - require.Equal(t, big.NewInt(42), balance) + assert.NoError(t, err) + assert.Equal(t, big.NewInt(42), balance) }) t.Run("can deposit non-gas coin for transfers", func(t *testing.T) { @@ -72,12 +72,12 @@ func TestKeeper_ZRC20DepositAndCallContract(t *testing.T) { common.CoinType_ERC20, assetAddress, ) - require.NoError(t, err) - require.False(t, contractCall) + assert.NoError(t, err) + assert.False(t, contractCall) balance, err := k.BalanceOfZRC4(ctx, zrc20, to) - require.NoError(t, err) - require.Equal(t, big.NewInt(42), balance) + assert.NoError(t, err) + assert.Equal(t, big.NewInt(42), balance) }) t.Run("should fail if trying to call a contract with data to a EOC", func(t *testing.T) { @@ -104,7 +104,7 @@ func TestKeeper_ZRC20DepositAndCallContract(t *testing.T) { common.CoinType_ERC20, assetAddress, ) - require.ErrorIs(t, err, types.ErrCallNonContract) + assert.ErrorIs(t, err, types.ErrCallNonContract) }) t.Run("can deposit coin for transfers with liquidity cap not reached", func(t *testing.T) { @@ -121,17 +121,17 @@ func TestKeeper_ZRC20DepositAndCallContract(t *testing.T) { // there is an initial total supply minted during gas pool setup initialTotalSupply, err := k.TotalSupplyZRC4(ctx, zrc20) - require.NoError(t, err) + assert.NoError(t, err) // set a liquidity cap coin, found := k.GetForeignCoins(ctx, zrc20.String()) - require.True(t, found) + assert.True(t, found) coin.LiquidityCap = math.NewUint(initialTotalSupply.Uint64() + 1000) k.SetForeignCoins(ctx, coin) // increase total supply _, err = k.DepositZRC20(ctx, zrc20, sample.EthAddress(), big.NewInt(500)) - require.NoError(t, err) + assert.NoError(t, err) // deposit to := sample.EthAddress() @@ -145,12 +145,12 @@ func TestKeeper_ZRC20DepositAndCallContract(t *testing.T) { common.CoinType_Gas, sample.EthAddress().String(), ) - require.NoError(t, err) - require.False(t, contractCall) + assert.NoError(t, err) + assert.False(t, contractCall) balance, err := k.BalanceOfZRC4(ctx, zrc20, to) - require.NoError(t, err) - require.Equal(t, big.NewInt(500), balance) + assert.NoError(t, err) + assert.Equal(t, big.NewInt(500), balance) }) t.Run("should fail if coin paused", func(t *testing.T) { @@ -167,7 +167,7 @@ func TestKeeper_ZRC20DepositAndCallContract(t *testing.T) { // pause the coin coin, found := k.GetForeignCoins(ctx, zrc20.String()) - require.True(t, found) + assert.True(t, found) coin.Paused = true k.SetForeignCoins(ctx, coin) @@ -182,7 +182,7 @@ func TestKeeper_ZRC20DepositAndCallContract(t *testing.T) { common.CoinType_Gas, sample.EthAddress().String(), ) - require.ErrorIs(t, err, types.ErrPausedZRC20) + assert.ErrorIs(t, err, types.ErrPausedZRC20) }) t.Run("should fail if liquidity cap reached", func(t *testing.T) { @@ -199,17 +199,17 @@ func TestKeeper_ZRC20DepositAndCallContract(t *testing.T) { // there is an initial total supply minted during gas pool setup initialTotalSupply, err := k.TotalSupplyZRC4(ctx, zrc20) - require.NoError(t, err) + assert.NoError(t, err) // set a liquidity cap coin, found := k.GetForeignCoins(ctx, zrc20.String()) - require.True(t, found) + assert.True(t, found) coin.LiquidityCap = math.NewUint(initialTotalSupply.Uint64() + 1000) k.SetForeignCoins(ctx, coin) // increase total supply _, err = k.DepositZRC20(ctx, zrc20, sample.EthAddress(), big.NewInt(500)) - require.NoError(t, err) + assert.NoError(t, err) // deposit (500 + 501 > 1000) to := sample.EthAddress() @@ -223,7 +223,7 @@ func TestKeeper_ZRC20DepositAndCallContract(t *testing.T) { common.CoinType_Gas, sample.EthAddress().String(), ) - require.ErrorIs(t, err, types.ErrForeignCoinCapReached) + assert.ErrorIs(t, err, types.ErrForeignCoinCapReached) }) t.Run("should fail if gas coin not found", func(t *testing.T) { @@ -249,7 +249,7 @@ func TestKeeper_ZRC20DepositAndCallContract(t *testing.T) { common.CoinType_Gas, sample.EthAddress().String(), ) - require.ErrorIs(t, err, crosschaintypes.ErrGasCoinNotFound) + assert.ErrorIs(t, err, crosschaintypes.ErrGasCoinNotFound) }) t.Run("should fail if zrc20 not found", func(t *testing.T) { @@ -275,7 +275,7 @@ func TestKeeper_ZRC20DepositAndCallContract(t *testing.T) { common.CoinType_ERC20, assetAddress, ) - require.ErrorIs(t, err, crosschaintypes.ErrForeignCoinNotFound) + assert.ErrorIs(t, err, crosschaintypes.ErrForeignCoinNotFound) }) t.Run("should return contract call if receiver is a contract", func(t *testing.T) { @@ -291,7 +291,7 @@ func TestKeeper_ZRC20DepositAndCallContract(t *testing.T) { zrc20 := setupGasCoin(t, ctx, k, sdkk.EvmKeeper, chain.ChainId, "foobar", "foobar") example, err := k.DeployContract(ctx, contracts.ExampleMetaData) - require.NoError(t, err) + assert.NoError(t, err) assertContractDeployment(t, sdkk.EvmKeeper, ctx, example) // deposit @@ -305,12 +305,12 @@ func TestKeeper_ZRC20DepositAndCallContract(t *testing.T) { common.CoinType_Gas, sample.EthAddress().String(), ) - require.NoError(t, err) - require.True(t, contractCall) + assert.NoError(t, err) + assert.True(t, contractCall) balance, err := k.BalanceOfZRC4(ctx, zrc20, example) - require.NoError(t, err) - require.Equal(t, big.NewInt(42), balance) + assert.NoError(t, err) + assert.Equal(t, big.NewInt(42), balance) // check onCrossChainCall() hook was called assertExampleBarValue(t, ctx, k, example, 42) @@ -329,7 +329,7 @@ func TestKeeper_ZRC20DepositAndCallContract(t *testing.T) { zrc20 := setupGasCoin(t, ctx, k, sdkk.EvmKeeper, chain.ChainId, "foobar", "foobar") reverter, err := k.DeployContract(ctx, contracts.ReverterMetaData) - require.NoError(t, err) + assert.NoError(t, err) assertContractDeployment(t, sdkk.EvmKeeper, ctx, reverter) // deposit @@ -343,11 +343,11 @@ func TestKeeper_ZRC20DepositAndCallContract(t *testing.T) { common.CoinType_Gas, sample.EthAddress().String(), ) - require.Error(t, err) - require.True(t, contractCall) + assert.Error(t, err) + assert.True(t, contractCall) balance, err := k.BalanceOfZRC4(ctx, zrc20, reverter) - require.NoError(t, err) - require.EqualValues(t, int64(0), balance.Int64()) + assert.NoError(t, err) + assert.EqualValues(t, int64(0), balance.Int64()) }) } diff --git a/x/fungible/keeper/evm_hooks_test.go b/x/fungible/keeper/evm_hooks_test.go index 43e8a58326..ae77d2d202 100644 --- a/x/fungible/keeper/evm_hooks_test.go +++ b/x/fungible/keeper/evm_hooks_test.go @@ -4,7 +4,7 @@ import ( "testing" ethtypes "github.com/ethereum/go-ethereum/core/types" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/fungible/types" @@ -97,15 +97,15 @@ func TestKeeper_CheckPausedZRC20(t *testing.T) { t.Run(tc.name, func(t *testing.T) { k, ctx, _, _ := keepertest.FungibleKeeper(t) - requireUnpaused := func(zrc20 string) { + assertUnpaused := func(zrc20 string) { fc, found := k.GetForeignCoins(ctx, zrc20) - require.True(t, found) - require.False(t, fc.Paused) + assert.True(t, found) + assert.False(t, fc.Paused) } - requirePaused := func(zrc20 string) { + assertPaused := func(zrc20 string) { fc, found := k.GetForeignCoins(ctx, zrc20) - require.True(t, found) - require.True(t, fc.Paused) + assert.True(t, found) + assert.True(t, fc.Paused) } // setup ZRC20 @@ -117,17 +117,17 @@ func TestKeeper_CheckPausedZRC20(t *testing.T) { k.SetForeignCoins(ctx, pausedZRC20) // check paused status - requireUnpaused(addrUnpausedZRC20A.Hex()) - requireUnpaused(addrUnpausedZRC20B.Hex()) - requireUnpaused(addrUnpausedZRC20C.Hex()) - requirePaused(addrPausedZRC20.Hex()) + assertUnpaused(addrUnpausedZRC20A.Hex()) + assertUnpaused(addrUnpausedZRC20B.Hex()) + assertUnpaused(addrUnpausedZRC20C.Hex()) + assertPaused(addrPausedZRC20.Hex()) // process test err := k.CheckPausedZRC20(ctx, tc.receipt) if tc.wantErr { - require.ErrorIs(t, err, types.ErrPausedZRC20) + assert.ErrorIs(t, err, types.ErrPausedZRC20) } else { - require.NoError(t, err) + assert.NoError(t, err) } }) } diff --git a/x/fungible/keeper/evm_test.go b/x/fungible/keeper/evm_test.go index 80bd42a2f3..877dc70c02 100644 --- a/x/fungible/keeper/evm_test.go +++ b/x/fungible/keeper/evm_test.go @@ -10,8 +10,8 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" evmkeeper "github.com/evmos/ethermint/x/evm/keeper" evmtypes "github.com/evmos/ethermint/x/evm/types" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" - "github.com/stretchr/testify/require" "github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/systemcontract.sol" zetacommon "github.com/zeta-chain/zetacore/common" "github.com/zeta-chain/zetacore/server/config" @@ -26,8 +26,8 @@ import ( // get a valid chain id independently of the build flag func getValidChainID(t *testing.T) int64 { list := zetacommon.DefaultChainsList() - require.NotEmpty(t, list) - require.NotNil(t, list[0]) + assert.NotEmpty(t, list) + assert.NotNil(t, list[0]) return list[0].ChainId } @@ -35,10 +35,10 @@ func getValidChainID(t *testing.T) int64 { // assert that a contract has been deployed by checking stored code is non-empty. func assertContractDeployment(t *testing.T, k *evmkeeper.Keeper, ctx sdk.Context, contractAddress common.Address) { acc := k.GetAccount(ctx, contractAddress) - require.NotNil(t, acc) + assert.NotNil(t, acc) code := k.GetCode(ctx, common.BytesToHash(acc.CodeHash)) - require.NotEmpty(t, code) + assert.NotEmpty(t, code) } // deploySystemContracts deploys the system contracts and returns their addresses. @@ -51,28 +51,28 @@ func deploySystemContracts( var err error wzeta, err = k.DeployWZETA(ctx) - require.NoError(t, err) - require.NotEmpty(t, wzeta) + assert.NoError(t, err) + assert.NotEmpty(t, wzeta) assertContractDeployment(t, evmk, ctx, wzeta) uniswapV2Factory, err = k.DeployUniswapV2Factory(ctx) - require.NoError(t, err) - require.NotEmpty(t, uniswapV2Factory) + assert.NoError(t, err) + assert.NotEmpty(t, uniswapV2Factory) assertContractDeployment(t, evmk, ctx, uniswapV2Factory) uniswapV2Router, err = k.DeployUniswapV2Router02(ctx, uniswapV2Factory, wzeta) - require.NoError(t, err) - require.NotEmpty(t, uniswapV2Router) + assert.NoError(t, err) + assert.NotEmpty(t, uniswapV2Router) assertContractDeployment(t, evmk, ctx, uniswapV2Router) connector, err = k.DeployConnectorZEVM(ctx, wzeta) - require.NoError(t, err) - require.NotEmpty(t, connector) + assert.NoError(t, err) + assert.NotEmpty(t, connector) assertContractDeployment(t, evmk, ctx, connector) systemContract, err = k.DeploySystemContract(ctx, wzeta, uniswapV2Factory, uniswapV2Router) - require.NoError(t, err) - require.NotEmpty(t, systemContract) + assert.NoError(t, err) + assert.NotEmpty(t, systemContract) assertContractDeployment(t, evmk, ctx, systemContract) return @@ -87,7 +87,7 @@ func assertExampleBarValue( expected int64, ) { exampleABI, err := contracts.ExampleMetaData.GetAbi() - require.NoError(t, err) + assert.NoError(t, err) res, err := k.CallEVM( ctx, *exampleABI, @@ -100,11 +100,11 @@ func assertExampleBarValue( "bar", ) unpacked, err := exampleABI.Unpack("bar", res.Ret) - require.NoError(t, err) - require.NotZero(t, len(unpacked)) + assert.NoError(t, err) + assert.NotZero(t, len(unpacked)) bar, ok := unpacked[0].(*big.Int) - require.True(t, ok) - require.Equal(t, big.NewInt(expected), bar) + assert.True(t, ok) + assert.Equal(t, big.NewInt(expected), bar) } func TestKeeper_DeployZRC20Contract(t *testing.T) { @@ -125,42 +125,42 @@ func TestKeeper_DeployZRC20Contract(t *testing.T) { "foobar", big.NewInt(1000), ) - require.NoError(t, err) + assert.NoError(t, err) assertContractDeployment(t, sdkk.EvmKeeper, ctx, addr) // check foreign coin foreignCoins, found := k.GetForeignCoins(ctx, addr.Hex()) - require.True(t, found) - require.Equal(t, "foobar", foreignCoins.Asset) - require.Equal(t, chainID, foreignCoins.ForeignChainId) - require.Equal(t, uint32(8), foreignCoins.Decimals) - require.Equal(t, "foo", foreignCoins.Name) - require.Equal(t, "bar", foreignCoins.Symbol) - require.Equal(t, zetacommon.CoinType_Gas, foreignCoins.CoinType) - require.Equal(t, uint64(1000), foreignCoins.GasLimit) + assert.True(t, found) + assert.Equal(t, "foobar", foreignCoins.Asset) + assert.Equal(t, chainID, foreignCoins.ForeignChainId) + assert.Equal(t, uint32(8), foreignCoins.Decimals) + assert.Equal(t, "foo", foreignCoins.Name) + assert.Equal(t, "bar", foreignCoins.Symbol) + assert.Equal(t, zetacommon.CoinType_Gas, foreignCoins.CoinType) + assert.Equal(t, uint64(1000), foreignCoins.GasLimit) // can get the zrc20 data zrc20Data, err := k.QueryZRC20Data(ctx, addr) - require.NoError(t, err) - require.Equal(t, "foo", zrc20Data.Name) - require.Equal(t, "bar", zrc20Data.Symbol) - require.Equal(t, uint8(8), zrc20Data.Decimals) + assert.NoError(t, err) + assert.Equal(t, "foo", zrc20Data.Name) + assert.Equal(t, "bar", zrc20Data.Symbol) + assert.Equal(t, uint8(8), zrc20Data.Decimals) // can deposit tokens to := sample.EthAddress() oldBalance, err := k.BalanceOfZRC4(ctx, addr, to) - require.NoError(t, err) - require.NotNil(t, oldBalance) - require.Equal(t, int64(0), oldBalance.Int64()) + assert.NoError(t, err) + assert.NotNil(t, oldBalance) + assert.Equal(t, int64(0), oldBalance.Int64()) amount := big.NewInt(100) _, err = k.DepositZRC20(ctx, addr, to, amount) - require.NoError(t, err) + assert.NoError(t, err) newBalance, err := k.BalanceOfZRC4(ctx, addr, to) - require.NoError(t, err) - require.NotNil(t, newBalance) - require.Equal(t, amount.Int64(), newBalance.Int64()) + assert.NoError(t, err) + assert.NotNil(t, newBalance) + assert.Equal(t, amount.Int64(), newBalance.Int64()) }) } @@ -174,23 +174,23 @@ func TestKeeper_DeploySystemContract(t *testing.T) { // can find system contract address found, err := k.GetSystemContractAddress(ctx) - require.NoError(t, err) - require.Equal(t, systemContract, found) + assert.NoError(t, err) + assert.Equal(t, systemContract, found) // can find factory address found, err = k.GetUniswapV2FactoryAddress(ctx) - require.NoError(t, err) - require.Equal(t, uniswapV2Factory, found) + assert.NoError(t, err) + assert.Equal(t, uniswapV2Factory, found) // can find router address found, err = k.GetUniswapV2Router02Address(ctx) - require.NoError(t, err) - require.Equal(t, uniswapV2Router, found) + assert.NoError(t, err) + assert.Equal(t, uniswapV2Router, found) // can find the wzeta contract address found, err = k.GetWZetaContractAddress(ctx) - require.NoError(t, err) - require.Equal(t, wzeta, found) + assert.NoError(t, err) + assert.Equal(t, wzeta, found) }) t.Run("can deposit into wzeta", func(t *testing.T) { @@ -200,21 +200,21 @@ func TestKeeper_DeploySystemContract(t *testing.T) { wzeta, _, _, _, _ := deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) balance, err := k.BalanceOfZRC4(ctx, wzeta, types.ModuleAddressEVM) - require.NoError(t, err) - require.NotNil(t, balance) - require.Equal(t, int64(0), balance.Int64()) + assert.NoError(t, err) + assert.NotNil(t, balance) + assert.Equal(t, int64(0), balance.Int64()) amount := big.NewInt(100) err = sdkk.BankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins(sdk.NewCoin("azeta", sdk.NewIntFromBigInt(amount)))) - require.NoError(t, err) + assert.NoError(t, err) err = k.CallWZetaDeposit(ctx, types.ModuleAddressEVM, amount) - require.NoError(t, err) + assert.NoError(t, err) balance, err = k.BalanceOfZRC4(ctx, wzeta, types.ModuleAddressEVM) - require.NoError(t, err) - require.NotNil(t, balance) - require.Equal(t, amount.Int64(), balance.Int64()) + assert.NoError(t, err) + assert.NotNil(t, balance) + assert.Equal(t, amount.Int64(), balance.Int64()) }) } @@ -228,7 +228,7 @@ func TestKeeper_DepositZRC20AndCallContract(t *testing.T) { zrc20 := setupGasCoin(t, ctx, k, sdkk.EvmKeeper, chainID, "foobar", "FOOBAR") example, err := k.DeployContract(ctx, contracts.ExampleMetaData) - require.NoError(t, err) + assert.NoError(t, err) assertContractDeployment(t, sdkk.EvmKeeper, ctx, example) res, err := k.DepositZRC20AndCallContract( @@ -243,15 +243,15 @@ func TestKeeper_DepositZRC20AndCallContract(t *testing.T) { big.NewInt(42), []byte(""), ) - require.NoError(t, err) - require.False(t, types.IsContractReverted(res, err)) + assert.NoError(t, err) + assert.False(t, types.IsContractReverted(res, err)) balance, err := k.BalanceOfZRC4(ctx, zrc20, example) - require.NoError(t, err) - require.Equal(t, int64(42), balance.Int64()) + assert.NoError(t, err) + assert.Equal(t, int64(42), balance.Int64()) // check onCrossChainCall has been called exampleABI, err := contracts.ExampleMetaData.GetAbi() - require.NoError(t, err) + assert.NoError(t, err) res, err = k.CallEVM( ctx, *exampleABI, @@ -264,11 +264,11 @@ func TestKeeper_DepositZRC20AndCallContract(t *testing.T) { "bar", ) unpacked, err := exampleABI.Unpack("bar", res.Ret) - require.NoError(t, err) - require.NotZero(t, len(unpacked)) + assert.NoError(t, err) + assert.NotZero(t, len(unpacked)) bar, ok := unpacked[0].(*big.Int) - require.True(t, ok) - require.Equal(t, big.NewInt(42), bar) + assert.True(t, ok) + assert.Equal(t, big.NewInt(42), bar) }) t.Run("should return a revert error when the underlying contract call revert", func(t *testing.T) { @@ -281,7 +281,7 @@ func TestKeeper_DepositZRC20AndCallContract(t *testing.T) { // Deploy reverter reverter, err := k.DeployContract(ctx, contracts.ReverterMetaData) - require.NoError(t, err) + assert.NoError(t, err) assertContractDeployment(t, sdkk.EvmKeeper, ctx, reverter) res, err := k.DepositZRC20AndCallContract( @@ -296,10 +296,10 @@ func TestKeeper_DepositZRC20AndCallContract(t *testing.T) { big.NewInt(42), []byte(""), ) - require.True(t, types.IsContractReverted(res, err)) + assert.True(t, types.IsContractReverted(res, err)) balance, err := k.BalanceOfZRC4(ctx, zrc20, reverter) - require.NoError(t, err) - require.Zero(t, balance.Int64()) + assert.NoError(t, err) + assert.Zero(t, balance.Int64()) }) t.Run("should revert if the underlying contract doesn't exist", func(t *testing.T) { @@ -322,7 +322,7 @@ func TestKeeper_DepositZRC20AndCallContract(t *testing.T) { big.NewInt(42), []byte(""), ) - require.True(t, types.IsContractReverted(res, err)) + assert.True(t, types.IsContractReverted(res, err)) }) } @@ -333,10 +333,10 @@ func TestKeeper_CallEVMWithData(t *testing.T) { // Deploy example contract, err := k.DeployContract(ctx, contracts.ExampleMetaData) - require.NoError(t, err) + assert.NoError(t, err) assertContractDeployment(t, sdkk.EvmKeeper, ctx, contract) abi, err := contracts.ExampleMetaData.GetAbi() - require.NoError(t, err) + assert.NoError(t, err) // doRevert make contract reverted res, err := k.CallEVM( @@ -350,12 +350,12 @@ func TestKeeper_CallEVMWithData(t *testing.T) { false, "doRevert", ) - require.Nil(t, res) - require.True(t, types.IsContractReverted(res, err)) + assert.Nil(t, res) + assert.True(t, types.IsContractReverted(res, err)) // check reason is included for revert error // 0xbfb4ebcf is the hash of "Foo()" - require.Contains(t, err.Error(), "reason: 0xbfb4ebcf") + assert.Contains(t, err.Error(), "reason: 0xbfb4ebcf") res, err = k.CallEVM( ctx, @@ -368,8 +368,8 @@ func TestKeeper_CallEVMWithData(t *testing.T) { false, "doRevertWithMessage", ) - require.Nil(t, res) - require.True(t, types.IsContractReverted(res, err)) + assert.Nil(t, res) + assert.True(t, types.IsContractReverted(res, err)) res, err = k.CallEVM( ctx, @@ -382,8 +382,8 @@ func TestKeeper_CallEVMWithData(t *testing.T) { false, "doRevertWithRequire", ) - require.Nil(t, res) - require.True(t, types.IsContractReverted(res, err)) + assert.Nil(t, res) + assert.True(t, types.IsContractReverted(res, err)) // Not a revert error if another type of error res, err = k.CallEVM( @@ -397,10 +397,10 @@ func TestKeeper_CallEVMWithData(t *testing.T) { false, "doNotExist", ) - require.Nil(t, res) - require.Error(t, err) - require.False(t, types.IsContractReverted(res, err)) - require.NotContains(t, err.Error(), "reason:") + assert.Nil(t, res) + assert.Error(t, err) + assert.False(t, types.IsContractReverted(res, err)) + assert.NotContains(t, err.Error(), "reason:") // No revert with successfull call res, err = k.CallEVM( @@ -414,9 +414,9 @@ func TestKeeper_CallEVMWithData(t *testing.T) { false, "doSucceed", ) - require.NotNil(t, res) - require.NoError(t, err) - require.False(t, types.IsContractReverted(res, err)) + assert.NotNil(t, res) + assert.NoError(t, err) + assert.False(t, types.IsContractReverted(res, err)) }) t.Run("apply new message without gas limit estimates gas", func(t *testing.T) { @@ -473,8 +473,8 @@ func TestKeeper_CallEVMWithData(t *testing.T) { big.NewInt(100), nil, ) - require.NoError(t, err) - require.Equal(t, msgRes, res) + assert.NoError(t, err) + assert.Equal(t, msgRes, res) // Assert that the expected methods were called mockAuthKeeper.AssertExpectations(t) @@ -523,8 +523,8 @@ func TestKeeper_CallEVMWithData(t *testing.T) { big.NewInt(100), big.NewInt(1000), ) - require.NoError(t, err) - require.Equal(t, msgRes, res) + assert.NoError(t, err) + assert.Equal(t, msgRes, res) // Assert that the expected methods were called mockAuthKeeper.AssertExpectations(t) @@ -549,7 +549,7 @@ func TestKeeper_CallEVMWithData(t *testing.T) { big.NewInt(100), nil, ) - require.ErrorIs(t, err, sample.ErrSample) + assert.ErrorIs(t, err, sample.ErrSample) }) t.Run("EstimateGas failure returns error", func(t *testing.T) { @@ -585,7 +585,7 @@ func TestKeeper_CallEVMWithData(t *testing.T) { big.NewInt(100), nil, ) - require.ErrorIs(t, err, sample.ErrSample) + assert.ErrorIs(t, err, sample.ErrSample) }) t.Run("ApplyMessage failure returns error", func(t *testing.T) { @@ -639,6 +639,6 @@ func TestKeeper_CallEVMWithData(t *testing.T) { big.NewInt(100), nil, ) - require.ErrorIs(t, err, sample.ErrSample) + assert.ErrorIs(t, err, sample.ErrSample) }) } diff --git a/x/fungible/keeper/foreign_coins_test.go b/x/fungible/keeper/foreign_coins_test.go index 0a5a0f37f0..c82f4d96be 100644 --- a/x/fungible/keeper/foreign_coins_test.go +++ b/x/fungible/keeper/foreign_coins_test.go @@ -4,7 +4,7 @@ import ( "strconv" "testing" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/common" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -68,12 +68,12 @@ func TestKeeper_GetGasCoinForForeignCoin(t *testing.T) { ) fc, found := k.GetGasCoinForForeignCoin(ctx, 1) - require.True(t, found) - require.Equal(t, "bar", fc.Name) + assert.True(t, found) + assert.Equal(t, "bar", fc.Name) fc, found = k.GetGasCoinForForeignCoin(ctx, 2) - require.False(t, found) + assert.False(t, found) fc, found = k.GetGasCoinForForeignCoin(ctx, 3) - require.False(t, found) + assert.False(t, found) } func TestKeeperGetForeignCoinFromAsset(t *testing.T) { @@ -122,16 +122,16 @@ func TestKeeperGetForeignCoinFromAsset(t *testing.T) { ) fc, found := k.GetForeignCoinFromAsset(ctx, gasAsset, 1) - require.True(t, found) - require.Equal(t, "bar", fc.Name) + assert.True(t, found) + assert.Equal(t, "bar", fc.Name) fc, found = k.GetForeignCoinFromAsset(ctx, sample.EthAddress().String(), 1) - require.False(t, found) + assert.False(t, found) fc, found = k.GetForeignCoinFromAsset(ctx, "invalid_address", 1) - require.False(t, found) + assert.False(t, found) fc, found = k.GetForeignCoinFromAsset(ctx, gasAsset, 2) - require.False(t, found) + assert.False(t, found) fc, found = k.GetForeignCoinFromAsset(ctx, gasAsset, 3) - require.False(t, found) + assert.False(t, found) }) t.Run("can get foreign coin with non-checksum address", func(t *testing.T) { @@ -148,7 +148,7 @@ func TestKeeperGetForeignCoinFromAsset(t *testing.T) { ) fc, found := k.GetForeignCoinFromAsset(ctx, "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", 1) - require.True(t, found) - require.Equal(t, "foo", fc.Name) + assert.True(t, found) + assert.Equal(t, "foo", fc.Name) }) } diff --git a/x/fungible/keeper/gas_coin_and_pool_test.go b/x/fungible/keeper/gas_coin_and_pool_test.go index 9bdd139fdc..196fc8a0fa 100644 --- a/x/fungible/keeper/gas_coin_and_pool_test.go +++ b/x/fungible/keeper/gas_coin_and_pool_test.go @@ -7,7 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/common" evmkeeper "github.com/evmos/ethermint/x/evm/keeper" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" testkeeper "github.com/zeta-chain/zetacore/testutil/keeper" fungiblekeeper "github.com/zeta-chain/zetacore/x/fungible/keeper" @@ -32,7 +32,7 @@ func setupGasCoin( 8, nil, ) - require.NoError(t, err) + assert.NoError(t, err) assertContractDeployment(t, evmk, ctx, addr) return addr } @@ -57,7 +57,7 @@ func deployZRC20( assetAddress, big.NewInt(21_000), ) - require.NoError(t, err) + assert.NoError(t, err) assertContractDeployment(t, evmk, ctx, addr) return addr } @@ -76,7 +76,7 @@ func TestKeeper_SetupChainGasCoinAndPool(t *testing.T) { // can retrieve the gas coin found, err := k.QuerySystemContractGasCoinZRC20(ctx, big.NewInt(chainID)) - require.NoError(t, err) - require.Equal(t, zrc20, found) + assert.NoError(t, err) + assert.Equal(t, zrc20, found) }) } diff --git a/x/fungible/keeper/gas_price_test.go b/x/fungible/keeper/gas_price_test.go index ec1bf267d8..d5295ed560 100644 --- a/x/fungible/keeper/gas_price_test.go +++ b/x/fungible/keeper/gas_price_test.go @@ -5,7 +5,7 @@ import ( "testing" ethcommon "github.com/ethereum/go-ethereum/common" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/systemcontract.sol" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -21,19 +21,19 @@ func TestKeeper_SetGasPrice(t *testing.T) { queryGasPrice := func(chainID *big.Int) *big.Int { abi, err := systemcontract.SystemContractMetaData.GetAbi() - require.NoError(t, err) + assert.NoError(t, err) res, err := k.CallEVM(ctx, *abi, types.ModuleAddressEVM, system, keeper.BigIntZero, nil, false, false, "gasPriceByChainId", chainID) - require.NoError(t, err) + assert.NoError(t, err) unpacked, err := abi.Unpack("gasPriceByChainId", res.Ret) - require.NoError(t, err) + assert.NoError(t, err) gasPrice, ok := unpacked[0].(*big.Int) - require.True(t, ok) + assert.True(t, ok) return gasPrice } _, err := k.SetGasPrice(ctx, big.NewInt(1), big.NewInt(42)) - require.NoError(t, err) - require.Equal(t, big.NewInt(42), queryGasPrice(big.NewInt(1))) + assert.NoError(t, err) + assert.Equal(t, big.NewInt(42), queryGasPrice(big.NewInt(1))) } func TestKeeper_SetGasCoin(t *testing.T) { @@ -43,11 +43,11 @@ func TestKeeper_SetGasCoin(t *testing.T) { deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) err := k.SetGasCoin(ctx, big.NewInt(1), gas) - require.NoError(t, err) + assert.NoError(t, err) found, err := k.QuerySystemContractGasCoinZRC20(ctx, big.NewInt(1)) - require.NoError(t, err) - require.Equal(t, gas.Hex(), found.Hex()) + assert.NoError(t, err) + assert.Equal(t, gas.Hex(), found.Hex()) } func TestKeeper_SetGasZetaPool(t *testing.T) { @@ -59,17 +59,17 @@ func TestKeeper_SetGasZetaPool(t *testing.T) { queryZetaPool := func(chainID *big.Int) ethcommon.Address { abi, err := systemcontract.SystemContractMetaData.GetAbi() - require.NoError(t, err) + assert.NoError(t, err) res, err := k.CallEVM(ctx, *abi, types.ModuleAddressEVM, system, keeper.BigIntZero, nil, false, false, "gasZetaPoolByChainId", chainID) - require.NoError(t, err) + assert.NoError(t, err) unpacked, err := abi.Unpack("gasZetaPoolByChainId", res.Ret) - require.NoError(t, err) + assert.NoError(t, err) pool, ok := unpacked[0].(ethcommon.Address) - require.True(t, ok) + assert.True(t, ok) return pool } err := k.SetGasZetaPool(ctx, big.NewInt(1), zrc20) - require.NoError(t, err) - require.NotEqual(t, ethcommon.Address{}, queryZetaPool(big.NewInt(1))) + assert.NoError(t, err) + assert.NotEqual(t, ethcommon.Address{}, queryZetaPool(big.NewInt(1))) } diff --git a/x/fungible/keeper/gas_stability_pool_test.go b/x/fungible/keeper/gas_stability_pool_test.go index 1c9bbc7b12..c2fb629267 100644 --- a/x/fungible/keeper/gas_stability_pool_test.go +++ b/x/fungible/keeper/gas_stability_pool_test.go @@ -4,7 +4,7 @@ import ( "math/big" "testing" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" testkeeper "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/x/fungible/types" ) @@ -15,21 +15,21 @@ func TestKeeper_EnsureGasStabilityPoolAccountCreated(t *testing.T) { // account doesn't exist acc := k.GetAuthKeeper().GetAccount(ctx, types.GasStabilityPoolAddress()) - require.Nil(t, acc) + assert.Nil(t, acc) // create the account k.EnsureGasStabilityPoolAccountCreated(ctx) acc = k.GetAuthKeeper().GetAccount(ctx, types.GasStabilityPoolAddress()) - require.NotNil(t, acc) - require.Equal(t, types.GasStabilityPoolAddress(), acc.GetAddress()) + assert.NotNil(t, acc) + assert.Equal(t, types.GasStabilityPoolAddress(), acc.GetAddress()) // can call the method again without side effects k.EnsureGasStabilityPoolAccountCreated(ctx) acc2 := k.GetAuthKeeper().GetAccount(ctx, types.GasStabilityPoolAddress()) - require.NotNil(t, acc2) - require.True(t, acc.GetAddress().Equals(acc2.GetAddress())) - require.Equal(t, acc.GetAccountNumber(), acc2.GetAccountNumber()) - require.Equal(t, acc.GetSequence(), acc2.GetSequence()) + assert.NotNil(t, acc2) + assert.True(t, acc.GetAddress().Equals(acc2.GetAddress())) + assert.Equal(t, acc.GetAccountNumber(), acc2.GetAccountNumber()) + assert.Equal(t, acc.GetSequence(), acc2.GetSequence()) }) } @@ -46,25 +46,25 @@ func TestKeeper_FundGasStabilityPool(t *testing.T) { // balance is initially 0 balance, err := k.GetGasStabilityPoolBalance(ctx, chainID) - require.NoError(t, err) - require.Equal(t, int64(0), balance.Int64()) + assert.NoError(t, err) + assert.Equal(t, int64(0), balance.Int64()) // fund the gas stability pool err = k.FundGasStabilityPool(ctx, chainID, big.NewInt(100)) - require.NoError(t, err) + assert.NoError(t, err) // balance is now 100 balance, err = k.GetGasStabilityPoolBalance(ctx, chainID) - require.NoError(t, err) - require.Equal(t, int64(100), balance.Int64()) + assert.NoError(t, err) + assert.Equal(t, int64(100), balance.Int64()) // withdraw from the gas stability pool err = k.WithdrawFromGasStabilityPool(ctx, chainID, big.NewInt(50)) - require.NoError(t, err) + assert.NoError(t, err) // balance is now 50 balance, err = k.GetGasStabilityPoolBalance(ctx, chainID) - require.NoError(t, err) - require.Equal(t, int64(50), balance.Int64()) + assert.NoError(t, err) + assert.Equal(t, int64(50), balance.Int64()) }) } diff --git a/x/fungible/keeper/grpc_query_code_hash_test.go b/x/fungible/keeper/grpc_query_code_hash_test.go index e2359dc530..43d1010c90 100644 --- a/x/fungible/keeper/grpc_query_code_hash_test.go +++ b/x/fungible/keeper/grpc_query_code_hash_test.go @@ -4,7 +4,7 @@ import ( "testing" ethcommon "github.com/ethereum/go-ethereum/common" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/fungible/types" @@ -17,14 +17,14 @@ func TestKeeper_CodeHash(t *testing.T) { wzeta, _, _, _, _ := deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) acc := sdkk.EvmKeeper.GetAccount(ctx, wzeta) - require.NotNil(t, acc) - require.NotNil(t, acc.CodeHash) + assert.NotNil(t, acc) + assert.NotNil(t, acc.CodeHash) res, err := k.CodeHash(ctx, &types.QueryCodeHashRequest{ Address: wzeta.Hex(), }) - require.NoError(t, err) - require.Equal(t, ethcommon.BytesToHash(acc.CodeHash).Hex(), res.CodeHash) + assert.NoError(t, err) + assert.Equal(t, ethcommon.BytesToHash(acc.CodeHash).Hex(), res.CodeHash) }) t.Run("should return error if address is invalid", func(t *testing.T) { @@ -33,8 +33,8 @@ func TestKeeper_CodeHash(t *testing.T) { _, err := k.CodeHash(ctx, &types.QueryCodeHashRequest{ Address: "invalid", }) - require.Error(t, err) - require.ErrorContains(t, err, "invalid address") + assert.Error(t, err) + assert.ErrorContains(t, err, "invalid address") }) t.Run("should return error if account not found", func(t *testing.T) { @@ -43,8 +43,8 @@ func TestKeeper_CodeHash(t *testing.T) { _, err := k.CodeHash(ctx, &types.QueryCodeHashRequest{ Address: sample.EthAddress().Hex(), }) - require.Error(t, err) - require.ErrorContains(t, err, "account not found") + assert.Error(t, err) + assert.ErrorContains(t, err, "account not found") }) t.Run("should return error if account is not a contract", func(t *testing.T) { @@ -54,7 +54,7 @@ func TestKeeper_CodeHash(t *testing.T) { _, err := k.CodeHash(ctx, &types.QueryCodeHashRequest{ Address: types.ModuleAddressEVM.Hex(), }) - require.Error(t, err) - require.ErrorContains(t, err, "account is not a contract") + assert.Error(t, err) + assert.ErrorContains(t, err, "account is not a contract") }) } diff --git a/x/fungible/keeper/grpc_query_foreign_coins_test.go b/x/fungible/keeper/grpc_query_foreign_coins_test.go index 76b4b2e7c0..bb9f641364 100644 --- a/x/fungible/keeper/grpc_query_foreign_coins_test.go +++ b/x/fungible/keeper/grpc_query_foreign_coins_test.go @@ -6,7 +6,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -54,10 +54,10 @@ func TestForeignCoinsQuerySingle(t *testing.T) { t.Run(tc.desc, func(t *testing.T) { response, err := keeper.ForeignCoins(wctx, tc.request) if tc.err != nil { - require.ErrorIs(t, err, tc.err) + assert.ErrorIs(t, err, tc.err) } else { - require.NoError(t, err) - require.Equal(t, + assert.NoError(t, err) + assert.Equal(t, nullify.Fill(tc.response), nullify.Fill(response), ) @@ -85,9 +85,9 @@ func TestForeignCoinsQueryPaginated(t *testing.T) { step := 2 for i := 0; i < len(msgs); i += step { resp, err := keeper.ForeignCoinsAll(wctx, request(nil, uint64(i), uint64(step), false)) - require.NoError(t, err) - require.LessOrEqual(t, len(resp.ForeignCoins), step) - require.Subset(t, + assert.NoError(t, err) + assert.LessOrEqual(t, len(resp.ForeignCoins), step) + assert.Subset(t, nullify.Fill(msgs), nullify.Fill(resp.ForeignCoins), ) @@ -98,9 +98,9 @@ func TestForeignCoinsQueryPaginated(t *testing.T) { var next []byte for i := 0; i < len(msgs); i += step { resp, err := keeper.ForeignCoinsAll(wctx, request(next, 0, uint64(step), false)) - require.NoError(t, err) - require.LessOrEqual(t, len(resp.ForeignCoins), step) - require.Subset(t, + assert.NoError(t, err) + assert.LessOrEqual(t, len(resp.ForeignCoins), step) + assert.Subset(t, nullify.Fill(msgs), nullify.Fill(resp.ForeignCoins), ) @@ -109,15 +109,15 @@ func TestForeignCoinsQueryPaginated(t *testing.T) { }) t.Run("Total", func(t *testing.T) { resp, err := keeper.ForeignCoinsAll(wctx, request(nil, 0, 0, true)) - require.NoError(t, err) - require.Equal(t, len(msgs), int(resp.Pagination.Total)) - require.ElementsMatch(t, + assert.NoError(t, err) + assert.Equal(t, len(msgs), int(resp.Pagination.Total)) + assert.ElementsMatch(t, nullify.Fill(msgs), nullify.Fill(resp.ForeignCoins), ) }) t.Run("InvalidRequest", func(t *testing.T) { _, err := keeper.ForeignCoinsAll(wctx, nil) - require.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) + assert.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) }) } diff --git a/x/fungible/keeper/grpc_query_params_test.go b/x/fungible/keeper/grpc_query_params_test.go index 634c6a38f6..377fe3f664 100644 --- a/x/fungible/keeper/grpc_query_params_test.go +++ b/x/fungible/keeper/grpc_query_params_test.go @@ -4,7 +4,7 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" testkeeper "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/x/fungible/types" ) @@ -16,6 +16,6 @@ func TestParamsQuery(t *testing.T) { keeper.SetParams(ctx, params) response, err := keeper.Params(wctx, &types.QueryParamsRequest{}) - require.NoError(t, err) - require.Equal(t, &types.QueryParamsResponse{Params: params}, response) + assert.NoError(t, err) + assert.Equal(t, &types.QueryParamsResponse{Params: params}, response) } diff --git a/x/fungible/keeper/msg_server_deploy_fungible_coin_zrc20_test.go b/x/fungible/keeper/msg_server_deploy_fungible_coin_zrc20_test.go index 1e64419f1a..b31725f422 100644 --- a/x/fungible/keeper/msg_server_deploy_fungible_coin_zrc20_test.go +++ b/x/fungible/keeper/msg_server_deploy_fungible_coin_zrc20_test.go @@ -6,7 +6,7 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ethcommon "github.com/ethereum/go-ethereum/common" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/common" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -36,24 +36,24 @@ func TestMsgServer_DeployFungibleCoinZRC20(t *testing.T) { common.CoinType_Gas, 1000000, )) - require.NoError(t, err) + assert.NoError(t, err) gasAddress := res.Address assertContractDeployment(t, sdkk.EvmKeeper, ctx, ethcommon.HexToAddress(gasAddress)) // can retrieve the gas coin foreignCoin, found := k.GetForeignCoins(ctx, gasAddress) - require.True(t, found) - require.Equal(t, foreignCoin.CoinType, common.CoinType_Gas) - require.Contains(t, foreignCoin.Name, "foo") + assert.True(t, found) + assert.Equal(t, foreignCoin.CoinType, common.CoinType_Gas) + assert.Contains(t, foreignCoin.Name, "foo") // check gas limit gasLimit, err := k.QueryGasLimit(ctx, ethcommon.HexToAddress(foreignCoin.Zrc20ContractAddress)) - require.NoError(t, err) - require.Equal(t, uint64(1000000), gasLimit.Uint64()) + assert.NoError(t, err) + assert.Equal(t, uint64(1000000), gasLimit.Uint64()) gas, err := k.QuerySystemContractGasCoinZRC20(ctx, big.NewInt(chainID)) - require.NoError(t, err) - require.Equal(t, gasAddress, gas.Hex()) + assert.NoError(t, err) + assert.Equal(t, gasAddress, gas.Hex()) // can deploy non-gas zrc20 res, err = msgServer.DeployFungibleCoinZRC20(ctx, types.NewMsgDeployFungibleCoinZRC20( @@ -66,24 +66,24 @@ func TestMsgServer_DeployFungibleCoinZRC20(t *testing.T) { common.CoinType_ERC20, 2000000, )) - require.NoError(t, err) + assert.NoError(t, err) assertContractDeployment(t, sdkk.EvmKeeper, ctx, ethcommon.HexToAddress(res.Address)) foreignCoin, found = k.GetForeignCoins(ctx, res.Address) - require.True(t, found) - require.Equal(t, foreignCoin.CoinType, common.CoinType_ERC20) - require.Contains(t, foreignCoin.Name, "bar") + assert.True(t, found) + assert.Equal(t, foreignCoin.CoinType, common.CoinType_ERC20) + assert.Contains(t, foreignCoin.Name, "bar") // check gas limit gasLimit, err = k.QueryGasLimit(ctx, ethcommon.HexToAddress(foreignCoin.Zrc20ContractAddress)) - require.NoError(t, err) - require.Equal(t, uint64(2000000), gasLimit.Uint64()) + assert.NoError(t, err) + assert.Equal(t, uint64(2000000), gasLimit.Uint64()) // gas should remain the same gas, err = k.QuerySystemContractGasCoinZRC20(ctx, big.NewInt(chainID)) - require.NoError(t, err) - require.NotEqual(t, res.Address, gas.Hex()) - require.Equal(t, gasAddress, gas.Hex()) + assert.NoError(t, err) + assert.NotEqual(t, res.Address, gas.Hex()) + assert.Equal(t, gasAddress, gas.Hex()) }) t.Run("should not deploy a new zrc20 if not admin", func(t *testing.T) { @@ -104,8 +104,8 @@ func TestMsgServer_DeployFungibleCoinZRC20(t *testing.T) { common.CoinType_Gas, 1000000, )) - require.Error(t, err) - require.ErrorIs(t, err, sdkerrors.ErrUnauthorized) + assert.Error(t, err) + assert.ErrorIs(t, err, sdkerrors.ErrUnauthorized) }) t.Run("should not deploy a new zrc20 with wrong decimal", func(t *testing.T) { @@ -128,8 +128,8 @@ func TestMsgServer_DeployFungibleCoinZRC20(t *testing.T) { common.CoinType_Gas, 1000000, )) - require.Error(t, err) - require.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) + assert.Error(t, err) + assert.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) }) t.Run("should not deploy a new zrc20 with invalid chain ID", func(t *testing.T) { @@ -151,8 +151,8 @@ func TestMsgServer_DeployFungibleCoinZRC20(t *testing.T) { common.CoinType_Gas, 1000000, )) - require.Error(t, err) - require.ErrorIs(t, err, observertypes.ErrSupportedChains) + assert.Error(t, err) + assert.ErrorIs(t, err, observertypes.ErrSupportedChains) }) t.Run("should not deploy an existing gas or erc20 contract", func(t *testing.T) { @@ -177,17 +177,17 @@ func TestMsgServer_DeployFungibleCoinZRC20(t *testing.T) { // Attempt to deploy the same gas token twice should result in error _, err := keeper.NewMsgServerImpl(*k).DeployFungibleCoinZRC20(ctx, deployMsg) - require.NoError(t, err) + assert.NoError(t, err) _, err = keeper.NewMsgServerImpl(*k).DeployFungibleCoinZRC20(ctx, deployMsg) - require.Error(t, err) - require.ErrorIs(t, err, types.ErrForeignCoinAlreadyExist) + assert.Error(t, err) + assert.ErrorIs(t, err, types.ErrForeignCoinAlreadyExist) // Similar to above, redeploying existing erc20 should also fail deployMsg.CoinType = common.CoinType_ERC20 _, err = keeper.NewMsgServerImpl(*k).DeployFungibleCoinZRC20(ctx, deployMsg) - require.NoError(t, err) + assert.NoError(t, err) _, err = keeper.NewMsgServerImpl(*k).DeployFungibleCoinZRC20(ctx, deployMsg) - require.Error(t, err) - require.ErrorIs(t, err, types.ErrForeignCoinAlreadyExist) + assert.Error(t, err) + assert.ErrorIs(t, err, types.ErrForeignCoinAlreadyExist) }) } diff --git a/x/fungible/keeper/msg_server_deploy_system_contract_test.go b/x/fungible/keeper/msg_server_deploy_system_contract_test.go index 86b9745021..601405d89c 100644 --- a/x/fungible/keeper/msg_server_deploy_system_contract_test.go +++ b/x/fungible/keeper/msg_server_deploy_system_contract_test.go @@ -8,7 +8,7 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ethcommon "github.com/ethereum/go-ethereum/common" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/fungible/keeper" @@ -25,8 +25,8 @@ func TestMsgServer_DeploySystemContracts(t *testing.T) { setAdminPolicies(ctx, zk, admin, observertypes.Policy_Type_group2) res, err := msgServer.DeploySystemContracts(ctx, types.NewMsgDeploySystemContracts(admin)) - require.NoError(t, err) - require.NotNil(t, res) + assert.NoError(t, err) + assert.NotNil(t, res) assertContractDeployment(t, sdkk.EvmKeeper, ctx, ethcommon.HexToAddress(res.UniswapV2Factory)) assertContractDeployment(t, sdkk.EvmKeeper, ctx, ethcommon.HexToAddress(res.Wzeta)) assertContractDeployment(t, sdkk.EvmKeeper, ctx, ethcommon.HexToAddress(res.UniswapV2Router)) @@ -42,7 +42,7 @@ func TestMsgServer_DeploySystemContracts(t *testing.T) { setAdminPolicies(ctx, zk, nonadmin, observertypes.Policy_Type_group1) _, err := msgServer.DeploySystemContracts(ctx, types.NewMsgDeploySystemContracts(nonadmin)) - require.ErrorIs(t, err, sdkerrors.ErrUnauthorized) + assert.ErrorIs(t, err, sdkerrors.ErrUnauthorized) }) t.Run("should fail if contract deployment fails", func(t *testing.T) { @@ -62,7 +62,7 @@ func TestMsgServer_DeploySystemContracts(t *testing.T) { ).Return(nil, errors.New("failed to estimate gas")) _, err := msgServer.DeploySystemContracts(ctx, types.NewMsgDeploySystemContracts(admin)) - require.Error(t, err) - require.Contains(t, err.Error(), "failed to deploy") + assert.Error(t, err) + assert.Contains(t, err.Error(), "failed to deploy") }) } diff --git a/x/fungible/keeper/msg_server_remove_foreign_coin_test.go b/x/fungible/keeper/msg_server_remove_foreign_coin_test.go index fedfe7315b..848e609b2f 100644 --- a/x/fungible/keeper/msg_server_remove_foreign_coin_test.go +++ b/x/fungible/keeper/msg_server_remove_foreign_coin_test.go @@ -4,7 +4,7 @@ import ( "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/fungible/keeper" @@ -25,12 +25,12 @@ func TestMsgServer_RemoveForeignCoin(t *testing.T) { zrc20 := setupGasCoin(t, ctx, k, sdkk.EvmKeeper, chainID, "foo", "foo") _, found := k.GetForeignCoins(ctx, zrc20.Hex()) - require.True(t, found) + assert.True(t, found) _, err := msgServer.RemoveForeignCoin(ctx, types.NewMsgRemoveForeignCoin(admin, zrc20.Hex())) - require.NoError(t, err) + assert.NoError(t, err) _, found = k.GetForeignCoins(ctx, zrc20.Hex()) - require.False(t, found) + assert.False(t, found) }) t.Run("should fail if not admin", func(t *testing.T) { @@ -43,8 +43,8 @@ func TestMsgServer_RemoveForeignCoin(t *testing.T) { zrc20 := setupGasCoin(t, ctx, k, sdkk.EvmKeeper, chainID, "foo", "foo") _, err := msgServer.RemoveForeignCoin(ctx, types.NewMsgRemoveForeignCoin(sample.AccAddress(), zrc20.Hex())) - require.Error(t, err) - require.ErrorIs(t, err, sdkerrors.ErrUnauthorized) + assert.Error(t, err) + assert.ErrorIs(t, err, sdkerrors.ErrUnauthorized) }) t.Run("should fail if not found", func(t *testing.T) { @@ -55,7 +55,7 @@ func TestMsgServer_RemoveForeignCoin(t *testing.T) { setAdminPolicies(ctx, zk, admin, observertypes.Policy_Type_group2) _, err := msgServer.RemoveForeignCoin(ctx, types.NewMsgRemoveForeignCoin(admin, sample.EthAddress().Hex())) - require.Error(t, err) - require.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) + assert.Error(t, err) + assert.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) }) } diff --git a/x/fungible/keeper/msg_server_udpate_zrc20_liquidity_cap_test.go b/x/fungible/keeper/msg_server_udpate_zrc20_liquidity_cap_test.go index ea51fabc14..f42286928a 100644 --- a/x/fungible/keeper/msg_server_udpate_zrc20_liquidity_cap_test.go +++ b/x/fungible/keeper/msg_server_udpate_zrc20_liquidity_cap_test.go @@ -5,7 +5,7 @@ import ( "cosmossdk.io/math" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/fungible/keeper" @@ -32,11 +32,11 @@ func TestMsgServer_UpdateZRC20LiquidityCap(t *testing.T) { coinAddress, math.NewUint(42), )) - require.NoError(t, err) + assert.NoError(t, err) coin, found := k.GetForeignCoins(ctx, coinAddress) - require.True(t, found) - require.True(t, coin.LiquidityCap.Equal(math.NewUint(42)), "invalid liquidity cap", coin.LiquidityCap.String()) + assert.True(t, found) + assert.True(t, coin.LiquidityCap.Equal(math.NewUint(42)), "invalid liquidity cap", coin.LiquidityCap.String()) // can update liquidity cap again _, err = msgServer.UpdateZRC20LiquidityCap(ctx, types.NewMsgUpdateZRC20LiquidityCap( @@ -44,11 +44,11 @@ func TestMsgServer_UpdateZRC20LiquidityCap(t *testing.T) { coinAddress, math.NewUint(4200000), )) - require.NoError(t, err) + assert.NoError(t, err) coin, found = k.GetForeignCoins(ctx, coinAddress) - require.True(t, found) - require.True(t, coin.LiquidityCap.Equal(math.NewUint(4200000)), "invalid liquidity cap", coin.LiquidityCap.String()) + assert.True(t, found) + assert.True(t, coin.LiquidityCap.Equal(math.NewUint(4200000)), "invalid liquidity cap", coin.LiquidityCap.String()) // can set liquidity cap to 0 _, err = msgServer.UpdateZRC20LiquidityCap(ctx, types.NewMsgUpdateZRC20LiquidityCap( @@ -56,11 +56,11 @@ func TestMsgServer_UpdateZRC20LiquidityCap(t *testing.T) { coinAddress, math.NewUint(0), )) - require.NoError(t, err) + assert.NoError(t, err) coin, found = k.GetForeignCoins(ctx, coinAddress) - require.True(t, found) - require.True(t, coin.LiquidityCap.Equal(math.ZeroUint()), "invalid liquidity cap", coin.LiquidityCap.String()) + assert.True(t, found) + assert.True(t, coin.LiquidityCap.Equal(math.ZeroUint()), "invalid liquidity cap", coin.LiquidityCap.String()) // can set liquidity cap to nil _, err = msgServer.UpdateZRC20LiquidityCap(ctx, types.NewMsgUpdateZRC20LiquidityCap( @@ -68,11 +68,11 @@ func TestMsgServer_UpdateZRC20LiquidityCap(t *testing.T) { coinAddress, math.Uint{}, )) - require.NoError(t, err) + assert.NoError(t, err) coin, found = k.GetForeignCoins(ctx, coinAddress) - require.True(t, found) - require.True(t, coin.LiquidityCap.Equal(math.ZeroUint()), "invalid liquidity cap", coin.LiquidityCap.String()) + assert.True(t, found) + assert.True(t, coin.LiquidityCap.Equal(math.ZeroUint()), "invalid liquidity cap", coin.LiquidityCap.String()) }) t.Run("should fail if not admin", func(t *testing.T) { @@ -92,8 +92,8 @@ func TestMsgServer_UpdateZRC20LiquidityCap(t *testing.T) { coinAddress, math.NewUint(42), )) - require.Error(t, err) - require.ErrorIs(t, err, sdkerrors.ErrUnauthorized) + assert.Error(t, err) + assert.ErrorIs(t, err, sdkerrors.ErrUnauthorized) }) t.Run("should fail if zrc20 does not exist", func(t *testing.T) { @@ -109,7 +109,7 @@ func TestMsgServer_UpdateZRC20LiquidityCap(t *testing.T) { coinAddress, math.NewUint(42), )) - require.Error(t, err) - require.ErrorIs(t, err, types.ErrForeignCoinNotFound) + assert.Error(t, err) + assert.ErrorIs(t, err, types.ErrForeignCoinNotFound) }) } diff --git a/x/fungible/keeper/msg_server_update_contract_bytecode_test.go b/x/fungible/keeper/msg_server_update_contract_bytecode_test.go index cb8e894eb0..f133236476 100644 --- a/x/fungible/keeper/msg_server_update_contract_bytecode_test.go +++ b/x/fungible/keeper/msg_server_update_contract_bytecode_test.go @@ -10,8 +10,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/evmos/ethermint/x/evm/statedb" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" - "github.com/stretchr/testify/require" zetacommon "github.com/zeta-chain/zetacore/common" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -35,7 +35,7 @@ func codeHashFromAddress(t *testing.T, ctx sdk.Context, k *keeper.Keeper, contra res, err := k.CodeHash(ctx, &types.QueryCodeHashRequest{ Address: contractAddr, }) - require.NoError(t, err) + assert.NoError(t, err) return res.CodeHash } @@ -51,10 +51,10 @@ func TestKeeper_UpdateContractBytecode(t *testing.T) { // sample chainIDs and addresses chainList := zetacommon.DefaultChainsList() - require.True(t, len(chainList) > 1) - require.NotNil(t, chainList[0]) - require.NotNil(t, chainList[1]) - require.NotEqual(t, chainList[0].ChainId, chainList[1].ChainId) + assert.True(t, len(chainList) > 1) + assert.NotNil(t, chainList[0]) + assert.NotNil(t, chainList[1]) + assert.NotEqual(t, chainList[0].ChainId, chainList[1].ChainId) chainID1 := chainList[0].ChainId chainID2 := chainList[1].ChainId @@ -67,28 +67,28 @@ func TestKeeper_UpdateContractBytecode(t *testing.T) { // do some operation to populate the state _, err := k.DepositZRC20(ctx, zrc20, addr1, big.NewInt(100)) - require.NoError(t, err) + assert.NoError(t, err) _, err = k.DepositZRC20(ctx, zrc20, addr2, big.NewInt(200)) - require.NoError(t, err) + assert.NoError(t, err) // check the state checkState := func() { // state that should not change balance, err := k.BalanceOfZRC4(ctx, zrc20, addr1) - require.NoError(t, err) - require.Equal(t, int64(100), balance.Int64()) + assert.NoError(t, err) + assert.Equal(t, int64(100), balance.Int64()) balance, err = k.BalanceOfZRC4(ctx, zrc20, addr2) - require.NoError(t, err) - require.Equal(t, int64(200), balance.Int64()) + assert.NoError(t, err) + assert.Equal(t, int64(200), balance.Int64()) totalSupply, err := k.TotalSupplyZRC4(ctx, zrc20) - require.NoError(t, err) - require.Equal(t, int64(10000300), totalSupply.Int64()) // 10000000 minted on deploy + assert.NoError(t, err) + assert.Equal(t, int64(10000300), totalSupply.Int64()) // 10000000 minted on deploy } checkState() chainID, err := k.QueryChainIDFromContract(ctx, zrc20) - require.NoError(t, err) - require.Equal(t, chainID1, chainID.Int64()) + assert.NoError(t, err) + assert.Equal(t, chainID1, chainID.Int64()) // deploy new zrc20 newCodeAddress, err := k.DeployZRC20Contract( @@ -101,7 +101,7 @@ func TestKeeper_UpdateContractBytecode(t *testing.T) { "beta", big.NewInt(90_000), ) - require.NoError(t, err) + assert.NoError(t, err) codeHash := codeHashFromAddress(t, ctx, k, newCodeAddress.Hex()) // update the bytecode @@ -110,29 +110,29 @@ func TestKeeper_UpdateContractBytecode(t *testing.T) { zrc20.Hex(), codeHash, )) - require.NoError(t, err) + assert.NoError(t, err) // check the returned new bytecode hash matches the one in the account acct := sdkk.EvmKeeper.GetAccount(ctx, zrc20) - require.Equal(t, acct.CodeHash, ethcommon.HexToHash(codeHash).Bytes()) + assert.Equal(t, acct.CodeHash, ethcommon.HexToHash(codeHash).Bytes()) // check the state // balances and total supply should remain // BYTECODE value is immutable and therefore part of the code, this value should change checkState() chainID, err = k.QueryChainIDFromContract(ctx, zrc20) - require.NoError(t, err) - require.Equal(t, chainID2, chainID.Int64()) + assert.NoError(t, err) + assert.Equal(t, chainID2, chainID.Int64()) // can continue to interact with the contract _, err = k.DepositZRC20(ctx, zrc20, addr1, big.NewInt(1000)) - require.NoError(t, err) + assert.NoError(t, err) balance, err := k.BalanceOfZRC4(ctx, zrc20, addr1) - require.NoError(t, err) - require.Equal(t, int64(1100), balance.Int64()) + assert.NoError(t, err) + assert.Equal(t, int64(1100), balance.Int64()) totalSupply, err := k.TotalSupplyZRC4(ctx, zrc20) - require.NoError(t, err) - require.Equal(t, int64(10001300), totalSupply.Int64()) + assert.NoError(t, err) + assert.Equal(t, int64(10001300), totalSupply.Int64()) // can change again bytecode newCodeAddress, err = k.DeployZRC20Contract( @@ -146,22 +146,22 @@ func TestKeeper_UpdateContractBytecode(t *testing.T) { big.NewInt(90_000), ) codeHash = codeHashFromAddress(t, ctx, k, newCodeAddress.Hex()) - require.NoError(t, err) + assert.NoError(t, err) _, err = msgServer.UpdateContractBytecode(ctx, types.NewMsgUpdateContractBytecode( admin, zrc20.Hex(), codeHash, )) - require.NoError(t, err) + assert.NoError(t, err) balance, err = k.BalanceOfZRC4(ctx, zrc20, addr1) - require.NoError(t, err) - require.Equal(t, int64(1100), balance.Int64()) + assert.NoError(t, err) + assert.Equal(t, int64(1100), balance.Int64()) totalSupply, err = k.TotalSupplyZRC4(ctx, zrc20) - require.NoError(t, err) - require.Equal(t, int64(10001300), totalSupply.Int64()) + assert.NoError(t, err) + assert.Equal(t, int64(10001300), totalSupply.Int64()) chainID, err = k.QueryChainIDFromContract(ctx, zrc20) - require.NoError(t, err) - require.Equal(t, chainID1, chainID.Int64()) + assert.NoError(t, err) + assert.Equal(t, chainID1, chainID.Int64()) }) t.Run("can update the bytecode of the wzeta connector contract", func(t *testing.T) { @@ -177,8 +177,8 @@ func TestKeeper_UpdateContractBytecode(t *testing.T) { // deploy a new connector that will become official connector newConnector, err := k.DeployConnectorZEVM(ctx, wzeta) - require.NoError(t, err) - require.NotEmpty(t, newConnector) + assert.NoError(t, err) + assert.NotEmpty(t, newConnector) assertContractDeployment(t, sdkk.EvmKeeper, ctx, newConnector) // can update the bytecode of the new connector with the old connector contract @@ -187,7 +187,7 @@ func TestKeeper_UpdateContractBytecode(t *testing.T) { newConnector.Hex(), codeHash, )) - require.NoError(t, err) + assert.NoError(t, err) }) t.Run("should fail if unauthorized", func(t *testing.T) { @@ -199,7 +199,7 @@ func TestKeeper_UpdateContractBytecode(t *testing.T) { sample.EthAddress().Hex(), sample.Hash().Hex(), )) - require.ErrorIs(t, err, sdkerrors.ErrUnauthorized) + assert.ErrorIs(t, err, sdkerrors.ErrUnauthorized) }) t.Run("should fail invalid contract address", func(t *testing.T) { @@ -214,7 +214,7 @@ func TestKeeper_UpdateContractBytecode(t *testing.T) { ContractAddress: "invalid", NewCodeHash: sample.Hash().Hex(), }) - require.ErrorIs(t, err, sdkerrors.ErrInvalidAddress) + assert.ErrorIs(t, err, sdkerrors.ErrInvalidAddress) }) t.Run("should fail if can't get contract account", func(t *testing.T) { @@ -238,7 +238,7 @@ func TestKeeper_UpdateContractBytecode(t *testing.T) { contractAddr.Hex(), sample.Hash().Hex(), )) - require.ErrorIs(t, err, types.ErrContractNotFound) + assert.ErrorIs(t, err, types.ErrContractNotFound) mockEVMKeeper.AssertExpectations(t) }) @@ -258,7 +258,7 @@ func TestKeeper_UpdateContractBytecode(t *testing.T) { wzeta.Hex(), sample.Hash().Hex(), )) - require.ErrorIs(t, err, types.ErrInvalidContract) + assert.ErrorIs(t, err, types.ErrInvalidContract) }) t.Run("should fail if system contract not found", func(t *testing.T) { @@ -279,7 +279,7 @@ func TestKeeper_UpdateContractBytecode(t *testing.T) { connector.Hex(), sample.Hash().Hex(), )) - require.ErrorIs(t, err, types.ErrSystemContractNotFound) + assert.ErrorIs(t, err, types.ErrSystemContractNotFound) }) t.Run("should fail if can't set account with new bytecode", func(t *testing.T) { @@ -316,7 +316,7 @@ func TestKeeper_UpdateContractBytecode(t *testing.T) { contractAddr.Hex(), newCodeHash, )) - require.ErrorIs(t, err, types.ErrSetBytecode) + assert.ErrorIs(t, err, types.ErrSetBytecode) mockEVMKeeper.AssertExpectations(t) }) diff --git a/x/fungible/keeper/msg_server_update_system_contract_test.go b/x/fungible/keeper/msg_server_update_system_contract_test.go index b464da209c..028d0ed215 100644 --- a/x/fungible/keeper/msg_server_update_system_contract_test.go +++ b/x/fungible/keeper/msg_server_update_system_contract_test.go @@ -6,7 +6,7 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/ethereum/go-ethereum/common" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/systemcontract.sol" "github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/zrc20.sol" zetacommon "github.com/zeta-chain/zetacore/common" @@ -27,20 +27,20 @@ func TestKeeper_UpdateSystemContract(t *testing.T) { queryZRC20SystemContract := func(contract common.Address) string { abi, err := zrc20.ZRC20MetaData.GetAbi() - require.NoError(t, err) + assert.NoError(t, err) res, err := k.CallEVM(ctx, *abi, types.ModuleAddressEVM, contract, keeper.BigIntZero, nil, false, false, "SYSTEM_CONTRACT_ADDRESS") - require.NoError(t, err) + assert.NoError(t, err) unpacked, err := abi.Unpack("SYSTEM_CONTRACT_ADDRESS", res.Ret) - require.NoError(t, err) + assert.NoError(t, err) address, ok := unpacked[0].(common.Address) - require.True(t, ok) + assert.True(t, ok) return address.Hex() } chains := zetacommon.DefaultChainsList() - require.True(t, len(chains) > 1) - require.NotNil(t, chains[0]) - require.NotNil(t, chains[1]) + assert.True(t, len(chains) > 1) + assert.NotNil(t, chains[0]) + assert.NotNil(t, chains[1]) chainID1 := chains[0].ChainId chainID2 := chains[1].ChainId @@ -50,28 +50,28 @@ func TestKeeper_UpdateSystemContract(t *testing.T) { // deploy a new system contracts newSystemContract, err := k.DeployContract(ctx, systemcontract.SystemContractMetaData, wzeta, factory, router) - require.NoError(t, err) - require.NotEqual(t, oldSystemContract, newSystemContract) + assert.NoError(t, err) + assert.NotEqual(t, oldSystemContract, newSystemContract) // can update the system contract _, err = msgServer.UpdateSystemContract(ctx, types.NewMsgUpdateSystemContract(admin, newSystemContract.Hex())) - require.NoError(t, err) + assert.NoError(t, err) // can retrieve the system contract sc, found := k.GetSystemContract(ctx) - require.True(t, found) - require.Equal(t, newSystemContract.Hex(), sc.SystemContract) + assert.True(t, found) + assert.Equal(t, newSystemContract.Hex(), sc.SystemContract) // check gas updated foundGas1, err := k.QuerySystemContractGasCoinZRC20(ctx, big.NewInt(chainID1)) - require.NoError(t, err) - require.Equal(t, gas1, foundGas1) + assert.NoError(t, err) + assert.Equal(t, gas1, foundGas1) foundGas2, err := k.QuerySystemContractGasCoinZRC20(ctx, big.NewInt(chainID2)) - require.NoError(t, err) - require.Equal(t, gas2, foundGas2) + assert.NoError(t, err) + assert.Equal(t, gas2, foundGas2) - require.Equal(t, newSystemContract.Hex(), queryZRC20SystemContract(gas1)) - require.Equal(t, newSystemContract.Hex(), queryZRC20SystemContract(gas2)) + assert.Equal(t, newSystemContract.Hex(), queryZRC20SystemContract(gas1)) + assert.Equal(t, newSystemContract.Hex(), queryZRC20SystemContract(gas2)) }) t.Run("should not update the system contract if not admin", func(t *testing.T) { @@ -82,13 +82,13 @@ func TestKeeper_UpdateSystemContract(t *testing.T) { // deploy a new system contracts wzeta, factory, router, _, oldSystemContract := deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) newSystemContract, err := k.DeployContract(ctx, systemcontract.SystemContractMetaData, wzeta, factory, router) - require.NoError(t, err) - require.NotEqual(t, oldSystemContract, newSystemContract) + assert.NoError(t, err) + assert.NotEqual(t, oldSystemContract, newSystemContract) // should not update the system contract if not admin _, err = msgServer.UpdateSystemContract(ctx, types.NewMsgUpdateSystemContract(sample.AccAddress(), newSystemContract.Hex())) - require.Error(t, err) - require.ErrorIs(t, err, sdkerrors.ErrUnauthorized) + assert.Error(t, err) + assert.ErrorIs(t, err, sdkerrors.ErrUnauthorized) }) t.Run("should not update the system contract if invalid address", func(t *testing.T) { @@ -101,12 +101,12 @@ func TestKeeper_UpdateSystemContract(t *testing.T) { // deploy a new system contracts wzeta, factory, router, _, oldSystemContract := deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) newSystemContract, err := k.DeployContract(ctx, systemcontract.SystemContractMetaData, wzeta, factory, router) - require.NoError(t, err) - require.NotEqual(t, oldSystemContract, newSystemContract) + assert.NoError(t, err) + assert.NotEqual(t, oldSystemContract, newSystemContract) // should not update the system contract if invalid address _, err = msgServer.UpdateSystemContract(ctx, types.NewMsgUpdateSystemContract(admin, "invalid")) - require.Error(t, err) - require.ErrorIs(t, err, sdkerrors.ErrInvalidAddress) + assert.Error(t, err) + assert.ErrorIs(t, err, sdkerrors.ErrInvalidAddress) }) } diff --git a/x/fungible/keeper/msg_server_update_zrc20_paused_status.go b/x/fungible/keeper/msg_server_update_zrc20_paused_status.go index fcbb37bfaa..3fe9380f2f 100644 --- a/x/fungible/keeper/msg_server_update_zrc20_paused_status.go +++ b/x/fungible/keeper/msg_server_update_zrc20_paused_status.go @@ -27,12 +27,12 @@ func (k msgServer) UpdateZRC20PausedStatus( } // check if the sender is the admin - // unpausing requires group2 admin - requirePolicyAccount := zetaObserverTypes.Policy_Type_group1 + // unpausing asserts group2 admin + assertPolicyAccount := zetaObserverTypes.Policy_Type_group1 if msg.Action == types.UpdatePausedStatusAction_UNPAUSE { - requirePolicyAccount = zetaObserverTypes.Policy_Type_group2 + assertPolicyAccount = zetaObserverTypes.Policy_Type_group2 } - if msg.Creator != k.observerKeeper.GetParams(ctx).GetAdminPolicyAccount(requirePolicyAccount) { + if msg.Creator != k.observerKeeper.GetParams(ctx).GetAdminPolicyAccount(assertPolicyAccount) { return nil, cosmoserrors.Wrap(sdkerrors.ErrUnauthorized, "Update can only be executed by the correct policy account") } diff --git a/x/fungible/keeper/msg_server_update_zrc20_paused_status_test.go b/x/fungible/keeper/msg_server_update_zrc20_paused_status_test.go index 2183cccf9c..bd6b69874e 100644 --- a/x/fungible/keeper/msg_server_update_zrc20_paused_status_test.go +++ b/x/fungible/keeper/msg_server_update_zrc20_paused_status_test.go @@ -4,7 +4,7 @@ import ( "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/fungible/keeper" @@ -18,15 +18,15 @@ func TestKeeper_UpdateZRC20PausedStatus(t *testing.T) { msgServer := keeper.NewMsgServerImpl(*k) admin := sample.AccAddress() - requireUnpaused := func(zrc20 string) { + assertUnpaused := func(zrc20 string) { fc, found := k.GetForeignCoins(ctx, zrc20) - require.True(t, found) - require.False(t, fc.Paused) + assert.True(t, found) + assert.False(t, fc.Paused) } - requirePaused := func(zrc20 string) { + assertPaused := func(zrc20 string) { fc, found := k.GetForeignCoins(ctx, zrc20) - require.True(t, found) - require.True(t, fc.Paused) + assert.True(t, found) + assert.True(t, fc.Paused) } // setup zrc20 @@ -34,9 +34,9 @@ func TestKeeper_UpdateZRC20PausedStatus(t *testing.T) { k.SetForeignCoins(ctx, sample.ForeignCoins(t, zrc20A)) k.SetForeignCoins(ctx, sample.ForeignCoins(t, zrc20B)) k.SetForeignCoins(ctx, sample.ForeignCoins(t, zrc20C)) - requireUnpaused(zrc20A) - requireUnpaused(zrc20B) - requireUnpaused(zrc20C) + assertUnpaused(zrc20A) + assertUnpaused(zrc20B) + assertUnpaused(zrc20C) setAdminPolicies(ctx, zk, admin, observertypes.Policy_Type_group1) @@ -49,10 +49,10 @@ func TestKeeper_UpdateZRC20PausedStatus(t *testing.T) { }, types.UpdatePausedStatusAction_PAUSE, )) - require.NoError(t, err) - requirePaused(zrc20A) - requirePaused(zrc20B) - requireUnpaused(zrc20C) + assert.NoError(t, err) + assertPaused(zrc20A) + assertPaused(zrc20B) + assertUnpaused(zrc20C) setAdminPolicies(ctx, zk, admin, observertypes.Policy_Type_group2) @@ -64,10 +64,10 @@ func TestKeeper_UpdateZRC20PausedStatus(t *testing.T) { }, types.UpdatePausedStatusAction_UNPAUSE, )) - require.NoError(t, err) - requireUnpaused(zrc20A) - requirePaused(zrc20B) - requireUnpaused(zrc20C) + assert.NoError(t, err) + assertUnpaused(zrc20A) + assertPaused(zrc20B) + assertUnpaused(zrc20C) setAdminPolicies(ctx, zk, admin, observertypes.Policy_Type_group1) @@ -79,10 +79,10 @@ func TestKeeper_UpdateZRC20PausedStatus(t *testing.T) { }, types.UpdatePausedStatusAction_PAUSE, )) - require.NoError(t, err) - requireUnpaused(zrc20A) - requirePaused(zrc20B) - requireUnpaused(zrc20C) + assert.NoError(t, err) + assertUnpaused(zrc20A) + assertPaused(zrc20B) + assertUnpaused(zrc20C) setAdminPolicies(ctx, zk, admin, observertypes.Policy_Type_group2) @@ -94,10 +94,10 @@ func TestKeeper_UpdateZRC20PausedStatus(t *testing.T) { }, types.UpdatePausedStatusAction_UNPAUSE, )) - require.NoError(t, err) - requireUnpaused(zrc20A) - requirePaused(zrc20B) - requireUnpaused(zrc20C) + assert.NoError(t, err) + assertUnpaused(zrc20A) + assertPaused(zrc20B) + assertUnpaused(zrc20C) setAdminPolicies(ctx, zk, admin, observertypes.Policy_Type_group1) @@ -111,10 +111,10 @@ func TestKeeper_UpdateZRC20PausedStatus(t *testing.T) { }, types.UpdatePausedStatusAction_PAUSE, )) - require.NoError(t, err) - requirePaused(zrc20A) - requirePaused(zrc20B) - requirePaused(zrc20C) + assert.NoError(t, err) + assertPaused(zrc20A) + assertPaused(zrc20B) + assertPaused(zrc20C) setAdminPolicies(ctx, zk, admin, observertypes.Policy_Type_group2) @@ -128,10 +128,10 @@ func TestKeeper_UpdateZRC20PausedStatus(t *testing.T) { }, types.UpdatePausedStatusAction_UNPAUSE, )) - require.NoError(t, err) - requireUnpaused(zrc20A) - requireUnpaused(zrc20B) - requireUnpaused(zrc20C) + assert.NoError(t, err) + assertUnpaused(zrc20A) + assertUnpaused(zrc20B) + assertUnpaused(zrc20C) }) t.Run("should fail if invalid message", func(t *testing.T) { @@ -141,10 +141,10 @@ func TestKeeper_UpdateZRC20PausedStatus(t *testing.T) { setAdminPolicies(ctx, zk, admin, observertypes.Policy_Type_group1) invalidMsg := types.NewMsgUpdateZRC20PausedStatus(admin, []string{}, types.UpdatePausedStatusAction_PAUSE) - require.ErrorIs(t, invalidMsg.ValidateBasic(), sdkerrors.ErrInvalidRequest) + assert.ErrorIs(t, invalidMsg.ValidateBasic(), sdkerrors.ErrInvalidRequest) _, err := msgServer.UpdateZRC20PausedStatus(ctx, invalidMsg) - require.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) + assert.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) }) t.Run("should fail if not authorized", func(t *testing.T) { @@ -166,7 +166,7 @@ func TestKeeper_UpdateZRC20PausedStatus(t *testing.T) { types.UpdatePausedStatusAction_UNPAUSE, )) - require.ErrorIs(t, err, sdkerrors.ErrUnauthorized) + assert.ErrorIs(t, err, sdkerrors.ErrUnauthorized) }) t.Run("should fail if zrc20 does not exist", func(t *testing.T) { @@ -188,6 +188,6 @@ func TestKeeper_UpdateZRC20PausedStatus(t *testing.T) { }, types.UpdatePausedStatusAction_PAUSE, )) - require.ErrorIs(t, err, types.ErrForeignCoinNotFound) + assert.ErrorIs(t, err, types.ErrForeignCoinNotFound) }) } diff --git a/x/fungible/keeper/msg_server_update_zrc20_withdraw_fee_test.go b/x/fungible/keeper/msg_server_update_zrc20_withdraw_fee_test.go index 108c70c664..288f158c31 100644 --- a/x/fungible/keeper/msg_server_update_zrc20_withdraw_fee_test.go +++ b/x/fungible/keeper/msg_server_update_zrc20_withdraw_fee_test.go @@ -9,8 +9,8 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" evmtypes "github.com/evmos/ethermint/x/evm/types" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" - "github.com/stretchr/testify/require" "github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/zrc20.sol" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -36,8 +36,8 @@ func TestKeeper_UpdateZRC20WithdrawFee(t *testing.T) { // initial protocol fee is zero protocolFee, err := k.QueryProtocolFlatFee(ctx, zrc20Addr) - require.NoError(t, err) - require.Zero(t, protocolFee.Uint64()) + assert.NoError(t, err) + assert.Zero(t, protocolFee.Uint64()) // can update the protocol fee and gas limit _, err = msgServer.UpdateZRC20WithdrawFee(ctx, types.NewMsgUpdateZRC20WithdrawFee( @@ -46,15 +46,15 @@ func TestKeeper_UpdateZRC20WithdrawFee(t *testing.T) { math.NewUint(42), math.NewUint(42), )) - require.NoError(t, err) + assert.NoError(t, err) // can query the updated fee protocolFee, err = k.QueryProtocolFlatFee(ctx, zrc20Addr) - require.NoError(t, err) - require.Equal(t, uint64(42), protocolFee.Uint64()) + assert.NoError(t, err) + assert.Equal(t, uint64(42), protocolFee.Uint64()) gasLimit, err := k.QueryGasLimit(ctx, zrc20Addr) - require.NoError(t, err) - require.Equal(t, uint64(42), gasLimit.Uint64()) + assert.NoError(t, err) + assert.Equal(t, uint64(42), gasLimit.Uint64()) // can update protocol fee only _, err = msgServer.UpdateZRC20WithdrawFee(ctx, types.NewMsgUpdateZRC20WithdrawFee( @@ -63,13 +63,13 @@ func TestKeeper_UpdateZRC20WithdrawFee(t *testing.T) { math.NewUint(43), math.Uint{}, )) - require.NoError(t, err) + assert.NoError(t, err) protocolFee, err = k.QueryProtocolFlatFee(ctx, zrc20Addr) - require.NoError(t, err) - require.Equal(t, uint64(43), protocolFee.Uint64()) + assert.NoError(t, err) + assert.Equal(t, uint64(43), protocolFee.Uint64()) gasLimit, err = k.QueryGasLimit(ctx, zrc20Addr) - require.NoError(t, err) - require.Equal(t, uint64(42), gasLimit.Uint64()) + assert.NoError(t, err) + assert.Equal(t, uint64(42), gasLimit.Uint64()) // can update gas limit only _, err = msgServer.UpdateZRC20WithdrawFee(ctx, types.NewMsgUpdateZRC20WithdrawFee( @@ -78,13 +78,13 @@ func TestKeeper_UpdateZRC20WithdrawFee(t *testing.T) { math.Uint{}, math.NewUint(44), )) - require.NoError(t, err) + assert.NoError(t, err) protocolFee, err = k.QueryProtocolFlatFee(ctx, zrc20Addr) - require.NoError(t, err) - require.Equal(t, uint64(43), protocolFee.Uint64()) + assert.NoError(t, err) + assert.Equal(t, uint64(43), protocolFee.Uint64()) gasLimit, err = k.QueryGasLimit(ctx, zrc20Addr) - require.NoError(t, err) - require.Equal(t, uint64(44), gasLimit.Uint64()) + assert.NoError(t, err) + assert.Equal(t, uint64(44), gasLimit.Uint64()) }) t.Run("should fail if not authorized", func(t *testing.T) { @@ -97,7 +97,7 @@ func TestKeeper_UpdateZRC20WithdrawFee(t *testing.T) { math.NewUint(42), math.Uint{}, )) - require.ErrorIs(t, err, sdkerrors.ErrUnauthorized) + assert.ErrorIs(t, err, sdkerrors.ErrUnauthorized) }) t.Run("should fail if invalid zrc20 address", func(t *testing.T) { @@ -112,7 +112,7 @@ func TestKeeper_UpdateZRC20WithdrawFee(t *testing.T) { math.NewUint(42), math.Uint{}, )) - require.ErrorIs(t, err, sdkerrors.ErrInvalidAddress) + assert.ErrorIs(t, err, sdkerrors.ErrInvalidAddress) }) t.Run("should fail if can't retrieve the foreign coin", func(t *testing.T) { @@ -127,7 +127,7 @@ func TestKeeper_UpdateZRC20WithdrawFee(t *testing.T) { math.NewUint(42), math.Uint{}, )) - require.ErrorIs(t, err, types.ErrForeignCoinNotFound) + assert.ErrorIs(t, err, types.ErrForeignCoinNotFound) }) t.Run("should fail if can't query old fee", func(t *testing.T) { @@ -148,7 +148,7 @@ func TestKeeper_UpdateZRC20WithdrawFee(t *testing.T) { math.NewUint(42), math.Uint{}, )) - require.ErrorIs(t, err, types.ErrContractCall) + assert.ErrorIs(t, err, types.ErrContractCall) }) t.Run("should fail if contract call for setting new protocol fee fails", func(t *testing.T) { @@ -173,9 +173,9 @@ func TestKeeper_UpdateZRC20WithdrawFee(t *testing.T) { // this is the query (commit == false) zrc20ABI, err := zrc20.ZRC20MetaData.GetAbi() - require.NoError(t, err) + assert.NoError(t, err) protocolFlatFee, err := zrc20ABI.Methods["PROTOCOL_FLAT_FEE"].Outputs.Pack(big.NewInt(42)) - require.NoError(t, err) + assert.NoError(t, err) mockEVMKeeper.On( "ApplyMessage", mock.Anything, @@ -185,7 +185,7 @@ func TestKeeper_UpdateZRC20WithdrawFee(t *testing.T) { ).Return(&evmtypes.MsgEthereumTxResponse{Ret: protocolFlatFee}, nil) gasLimit, err := zrc20ABI.Methods["GAS_LIMIT"].Outputs.Pack(big.NewInt(42)) - require.NoError(t, err) + assert.NoError(t, err) mockEVMKeeper.On( "ApplyMessage", mock.Anything, @@ -209,7 +209,7 @@ func TestKeeper_UpdateZRC20WithdrawFee(t *testing.T) { math.NewUint(42), math.Uint{}, )) - require.ErrorIs(t, err, types.ErrContractCall) + assert.ErrorIs(t, err, types.ErrContractCall) mockEVMKeeper.AssertExpectations(t) }) @@ -236,9 +236,9 @@ func TestKeeper_UpdateZRC20WithdrawFee(t *testing.T) { // this is the query (commit == false) zrc20ABI, err := zrc20.ZRC20MetaData.GetAbi() - require.NoError(t, err) + assert.NoError(t, err) protocolFlatFee, err := zrc20ABI.Methods["PROTOCOL_FLAT_FEE"].Outputs.Pack(big.NewInt(42)) - require.NoError(t, err) + assert.NoError(t, err) mockEVMKeeper.On( "ApplyMessage", mock.Anything, @@ -248,7 +248,7 @@ func TestKeeper_UpdateZRC20WithdrawFee(t *testing.T) { ).Return(&evmtypes.MsgEthereumTxResponse{Ret: protocolFlatFee}, nil) gasLimit, err := zrc20ABI.Methods["GAS_LIMIT"].Outputs.Pack(big.NewInt(42)) - require.NoError(t, err) + assert.NoError(t, err) mockEVMKeeper.On( "ApplyMessage", mock.Anything, @@ -272,7 +272,7 @@ func TestKeeper_UpdateZRC20WithdrawFee(t *testing.T) { math.Uint{}, math.NewUint(42), )) - require.ErrorIs(t, err, types.ErrContractCall) + assert.ErrorIs(t, err, types.ErrContractCall) mockEVMKeeper.AssertExpectations(t) }) diff --git a/x/fungible/keeper/params_test.go b/x/fungible/keeper/params_test.go index b3b9497a74..377e13b4ce 100644 --- a/x/fungible/keeper/params_test.go +++ b/x/fungible/keeper/params_test.go @@ -3,7 +3,7 @@ package keeper_test import ( "testing" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" testkeeper "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/x/fungible/types" ) @@ -14,5 +14,5 @@ func TestGetParams(t *testing.T) { k.SetParams(ctx, params) - require.EqualValues(t, params, k.GetParams(ctx)) + assert.EqualValues(t, params, k.GetParams(ctx)) } diff --git a/x/fungible/keeper/system_contract_test.go b/x/fungible/keeper/system_contract_test.go index 3874f52435..3148b8c44c 100644 --- a/x/fungible/keeper/system_contract_test.go +++ b/x/fungible/keeper/system_contract_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/ethereum/go-ethereum/common" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/fungible/types" @@ -15,13 +15,13 @@ func TestKeeper_GetSystemContract(t *testing.T) { k, ctx, _, _ := keepertest.FungibleKeeper(t) k.SetSystemContract(ctx, types.SystemContract{SystemContract: "test"}) val, found := k.GetSystemContract(ctx) - require.True(t, found) - require.Equal(t, types.SystemContract{SystemContract: "test"}, val) + assert.True(t, found) + assert.Equal(t, types.SystemContract{SystemContract: "test"}, val) // can remove contract k.RemoveSystemContract(ctx) _, found = k.GetSystemContract(ctx) - require.False(t, found) + assert.False(t, found) } func TestKeeper_GetSystemContractAddress(t *testing.T) { @@ -29,13 +29,13 @@ func TestKeeper_GetSystemContractAddress(t *testing.T) { k.GetAuthKeeper().GetModuleAccount(ctx, types.ModuleName) _, err := k.GetSystemContractAddress(ctx) - require.Error(t, err) - require.ErrorIs(t, err, types.ErrStateVariableNotFound) + assert.Error(t, err) + assert.ErrorIs(t, err, types.ErrStateVariableNotFound) _, _, _, _, systemContract := deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) found, err := k.GetSystemContractAddress(ctx) - require.NoError(t, err) - require.Equal(t, systemContract, found) + assert.NoError(t, err) + assert.Equal(t, systemContract, found) } func TestKeeper_GetWZetaContractAddress(t *testing.T) { @@ -43,13 +43,13 @@ func TestKeeper_GetWZetaContractAddress(t *testing.T) { k.GetAuthKeeper().GetModuleAccount(ctx, types.ModuleName) _, err := k.GetWZetaContractAddress(ctx) - require.Error(t, err) - require.ErrorIs(t, err, types.ErrStateVariableNotFound) + assert.Error(t, err) + assert.ErrorIs(t, err, types.ErrStateVariableNotFound) wzeta, _, _, _, _ := deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) found, err := k.GetWZetaContractAddress(ctx) - require.NoError(t, err) - require.Equal(t, wzeta, found) + assert.NoError(t, err) + assert.Equal(t, wzeta, found) } func TestKeeper_GetUniswapV2FactoryAddress(t *testing.T) { @@ -57,13 +57,13 @@ func TestKeeper_GetUniswapV2FactoryAddress(t *testing.T) { k.GetAuthKeeper().GetModuleAccount(ctx, types.ModuleName) _, err := k.GetUniswapV2FactoryAddress(ctx) - require.Error(t, err) - require.ErrorIs(t, err, types.ErrStateVariableNotFound) + assert.Error(t, err) + assert.ErrorIs(t, err, types.ErrStateVariableNotFound) _, factory, _, _, _ := deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) found, err := k.GetUniswapV2FactoryAddress(ctx) - require.NoError(t, err) - require.Equal(t, factory, found) + assert.NoError(t, err) + assert.Equal(t, factory, found) } func TestKeeper_GetUniswapV2Router02Address(t *testing.T) { @@ -71,13 +71,13 @@ func TestKeeper_GetUniswapV2Router02Address(t *testing.T) { k.GetAuthKeeper().GetModuleAccount(ctx, types.ModuleName) _, err := k.GetUniswapV2Router02Address(ctx) - require.Error(t, err) - require.ErrorIs(t, err, types.ErrStateVariableNotFound) + assert.Error(t, err) + assert.ErrorIs(t, err, types.ErrStateVariableNotFound) _, _, router, _, _ := deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) found, err := k.GetUniswapV2Router02Address(ctx) - require.NoError(t, err) - require.Equal(t, router, found) + assert.NoError(t, err) + assert.Equal(t, router, found) } func TestKeeper_CallWZetaDeposit(t *testing.T) { @@ -89,23 +89,23 @@ func TestKeeper_CallWZetaDeposit(t *testing.T) { ethAddr := common.BytesToAddress(addr.Bytes()) coins := sample.Coins() err := sdkk.BankKeeper.MintCoins(ctx, types.ModuleName, sample.Coins()) - require.NoError(t, err) + assert.NoError(t, err) err = sdkk.BankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, addr, coins) - require.NoError(t, err) + assert.NoError(t, err) // fail if no system contract err = k.CallWZetaDeposit(ctx, ethAddr, big.NewInt(42)) - require.Error(t, err) + assert.Error(t, err) deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) // deposit err = k.CallWZetaDeposit(ctx, ethAddr, big.NewInt(42)) - require.NoError(t, err) + assert.NoError(t, err) balance, err := k.QueryWZetaBalanceOf(ctx, ethAddr) - require.NoError(t, err) - require.Equal(t, big.NewInt(42), balance) + assert.NoError(t, err) + assert.Equal(t, big.NewInt(42), balance) } func TestKeeper_QuerySystemContractGasCoinZRC20(t *testing.T) { @@ -114,13 +114,13 @@ func TestKeeper_QuerySystemContractGasCoinZRC20(t *testing.T) { chainID := getValidChainID(t) _, err := k.QuerySystemContractGasCoinZRC20(ctx, big.NewInt(chainID)) - require.Error(t, err) - require.ErrorIs(t, err, types.ErrStateVariableNotFound) + assert.Error(t, err) + assert.ErrorIs(t, err, types.ErrStateVariableNotFound) deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) zrc20 := setupGasCoin(t, ctx, k, sdkk.EvmKeeper, chainID, "foobar", "foobar") found, err := k.QuerySystemContractGasCoinZRC20(ctx, big.NewInt(chainID)) - require.NoError(t, err) - require.Equal(t, zrc20, found) + assert.NoError(t, err) + assert.Equal(t, zrc20, found) } diff --git a/x/fungible/keeper/zeta_test.go b/x/fungible/keeper/zeta_test.go index cec34d06ea..4eea6b70ad 100644 --- a/x/fungible/keeper/zeta_test.go +++ b/x/fungible/keeper/zeta_test.go @@ -6,7 +6,7 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/cmd/zetacored/config" testkeeper "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -20,12 +20,12 @@ func TestKeeper_MintZetaToEVMAccount(t *testing.T) { acc := sample.Bech32AccAddress() bal := sdkk.BankKeeper.GetBalance(ctx, acc, config.BaseDenom) - require.True(t, bal.IsZero()) + assert.True(t, bal.IsZero()) err := k.MintZetaToEVMAccount(ctx, acc, big.NewInt(42)) - require.NoError(t, err) + assert.NoError(t, err) bal = sdkk.BankKeeper.GetBalance(ctx, acc, config.BaseDenom) - require.True(t, bal.Amount.Equal(sdk.NewInt(42))) + assert.True(t, bal.Amount.Equal(sdk.NewInt(42))) }) coins42 := sdk.NewCoins(sdk.NewCoin(config.BaseDenom, sdk.NewInt(42))) @@ -43,7 +43,7 @@ func TestKeeper_MintZetaToEVMAccount(t *testing.T) { ).Return(errors.New("error")) err := k.MintZetaToEVMAccount(ctx, sample.Bech32AccAddress(), big.NewInt(42)) - require.Error(t, err) + assert.Error(t, err) mockBankKeeper.AssertExpectations(t) }) @@ -70,7 +70,7 @@ func TestKeeper_MintZetaToEVMAccount(t *testing.T) { ).Return(errors.New("error")) err := k.MintZetaToEVMAccount(ctx, acc, big.NewInt(42)) - require.Error(t, err) + assert.Error(t, err) mockBankKeeper.AssertExpectations(t) }) diff --git a/x/fungible/types/evm_test.go b/x/fungible/types/evm_test.go index 0be4d916da..4e81bb3562 100644 --- a/x/fungible/types/evm_test.go +++ b/x/fungible/types/evm_test.go @@ -7,16 +7,16 @@ import ( "github.com/ethereum/go-ethereum/core/vm" evmtypes "github.com/evmos/ethermint/x/evm/types" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/x/fungible/types" ) func TestIsContractReverted(t *testing.T) { - require.True(t, types.IsContractReverted(nil, vm.ErrExecutionReverted)) - require.True(t, types.IsContractReverted(nil, fmt.Errorf("foo : %s", vm.ErrExecutionReverted.Error()))) - require.True(t, types.IsContractReverted(&evmtypes.MsgEthereumTxResponse{VmError: "foo"}, nil)) + assert.True(t, types.IsContractReverted(nil, vm.ErrExecutionReverted)) + assert.True(t, types.IsContractReverted(nil, fmt.Errorf("foo : %s", vm.ErrExecutionReverted.Error()))) + assert.True(t, types.IsContractReverted(&evmtypes.MsgEthereumTxResponse{VmError: "foo"}, nil)) - require.False(t, types.IsContractReverted(nil, nil)) - require.False(t, types.IsContractReverted(nil, errors.New("foo"))) - require.False(t, types.IsContractReverted(&evmtypes.MsgEthereumTxResponse{VmError: ""}, nil)) + assert.False(t, types.IsContractReverted(nil, nil)) + assert.False(t, types.IsContractReverted(nil, errors.New("foo"))) + assert.False(t, types.IsContractReverted(&evmtypes.MsgEthereumTxResponse{VmError: ""}, nil)) } diff --git a/x/fungible/types/gas_stablity_pool_test.go b/x/fungible/types/gas_stablity_pool_test.go index c0ec0000f5..dfeac5b484 100644 --- a/x/fungible/types/gas_stablity_pool_test.go +++ b/x/fungible/types/gas_stablity_pool_test.go @@ -3,16 +3,16 @@ package types_test import ( "testing" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/x/fungible/types" ) func TestGetGasStabilityPoolAddress(t *testing.T) { address := types.GasStabilityPoolAddress() - require.False(t, address.Empty()) + assert.False(t, address.Empty()) } func TestGetGasStabilityPoolAddressEVM(t *testing.T) { address := types.GasStabilityPoolAddressEVM() - require.NotEmpty(t, address) + assert.NotEmpty(t, address) } diff --git a/x/fungible/types/genesis_test.go b/x/fungible/types/genesis_test.go index 57927528af..a5a16ba6f7 100644 --- a/x/fungible/types/genesis_test.go +++ b/x/fungible/types/genesis_test.go @@ -3,7 +3,7 @@ package types_test import ( "testing" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/x/fungible/types" ) @@ -51,9 +51,9 @@ func TestGenesisState_Validate(t *testing.T) { t.Run(tc.desc, func(t *testing.T) { err := tc.genState.Validate() if tc.valid { - require.NoError(t, err) + assert.NoError(t, err) } else { - require.Error(t, err) + assert.Error(t, err) } }) } diff --git a/x/fungible/types/message_deploy_fungible_coin_zrc20_test.go b/x/fungible/types/message_deploy_fungible_coin_zrc20_test.go index e107af7781..9addfd0eb5 100644 --- a/x/fungible/types/message_deploy_fungible_coin_zrc20_test.go +++ b/x/fungible/types/message_deploy_fungible_coin_zrc20_test.go @@ -4,7 +4,7 @@ import ( "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/fungible/types" ) @@ -49,10 +49,10 @@ func TestMsgDeployFungibleCoinZRC4_ValidateBasic(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - require.ErrorIs(t, err, tt.err) + assert.ErrorIs(t, err, tt.err) return } - require.NoError(t, err) + assert.NoError(t, err) }) } } diff --git a/x/fungible/types/message_deploy_system_contracts_test.go b/x/fungible/types/message_deploy_system_contracts_test.go index b14aa419ed..ff4b7111fd 100644 --- a/x/fungible/types/message_deploy_system_contracts_test.go +++ b/x/fungible/types/message_deploy_system_contracts_test.go @@ -4,7 +4,7 @@ import ( "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/fungible/types" ) @@ -33,10 +33,10 @@ func TestMsgDeploySystemContract_ValidateBasic(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - require.ErrorIs(t, err, tt.err) + assert.ErrorIs(t, err, tt.err) return } - require.NoError(t, err) + assert.NoError(t, err) }) } } diff --git a/x/fungible/types/message_remove_foreign_coin_test.go b/x/fungible/types/message_remove_foreign_coin_test.go index 66a4c143f3..b5949c722f 100644 --- a/x/fungible/types/message_remove_foreign_coin_test.go +++ b/x/fungible/types/message_remove_foreign_coin_test.go @@ -4,7 +4,7 @@ import ( "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/fungible/types" ) @@ -33,10 +33,10 @@ func TestMsgRemoveForeignCoin_ValidateBasic(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - require.ErrorIs(t, err, tt.err) + assert.ErrorIs(t, err, tt.err) return } - require.NoError(t, err) + assert.NoError(t, err) }) } } diff --git a/x/fungible/types/message_update_contract_bytecode_test.go b/x/fungible/types/message_update_contract_bytecode_test.go index 02e8b3cfdd..9e7d0970cd 100644 --- a/x/fungible/types/message_update_contract_bytecode_test.go +++ b/x/fungible/types/message_update_contract_bytecode_test.go @@ -3,7 +3,7 @@ package types_test import ( "testing" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/fungible/types" ) @@ -56,9 +56,9 @@ func TestMsgUpdateContractBytecode_ValidateBasic(t *testing.T) { t.Run(tc.name, func(t *testing.T) { err := tc.msg.ValidateBasic() if tc.wantError { - require.Error(t, err) + assert.Error(t, err) } else { - require.NoError(t, err) + assert.NoError(t, err) } }) } diff --git a/x/fungible/types/message_update_system_contract_test.go b/x/fungible/types/message_update_system_contract_test.go index 8ee196ad39..00ce59b4ab 100644 --- a/x/fungible/types/message_update_system_contract_test.go +++ b/x/fungible/types/message_update_system_contract_test.go @@ -4,7 +4,7 @@ import ( "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/fungible/types" ) @@ -43,10 +43,10 @@ func TestMsgUpdateSystemContract_ValidateBasic(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - require.ErrorIs(t, err, tt.err) + assert.ErrorIs(t, err, tt.err) return } - require.NoError(t, err) + assert.NoError(t, err) }) } } diff --git a/x/fungible/types/message_update_zrc20_liquidity_cap_test.go b/x/fungible/types/message_update_zrc20_liquidity_cap_test.go index d59198ce39..f62193d63e 100644 --- a/x/fungible/types/message_update_zrc20_liquidity_cap_test.go +++ b/x/fungible/types/message_update_zrc20_liquidity_cap_test.go @@ -6,7 +6,7 @@ import ( "cosmossdk.io/math" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/fungible/types" ) @@ -61,10 +61,10 @@ func TestNewMsgUpdateZRC20LiquidityCap_ValidateBasics(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - require.ErrorIs(t, err, tt.err) + assert.ErrorIs(t, err, tt.err) return } - require.NoError(t, err) + assert.NoError(t, err) }) } } diff --git a/x/fungible/types/message_update_zrc20_paused_status_test.go b/x/fungible/types/message_update_zrc20_paused_status_test.go index 326af3fe96..40ddf7c3ae 100644 --- a/x/fungible/types/message_update_zrc20_paused_status_test.go +++ b/x/fungible/types/message_update_zrc20_paused_status_test.go @@ -3,7 +3,7 @@ package types_test import ( "testing" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/fungible/types" ) @@ -94,9 +94,9 @@ func TestMMsgUpdateZRC20PausedStatus_ValidateBasic(t *testing.T) { t.Run(tc.name, func(t *testing.T) { err := tc.msg.ValidateBasic() if tc.wantErr { - require.Error(t, err) + assert.Error(t, err) } else { - require.NoError(t, err) + assert.NoError(t, err) } }) } diff --git a/x/fungible/types/message_update_zrc20_withdraw_fee_test.go b/x/fungible/types/message_update_zrc20_withdraw_fee_test.go index 2aba73d42a..232dae1a46 100644 --- a/x/fungible/types/message_update_zrc20_withdraw_fee_test.go +++ b/x/fungible/types/message_update_zrc20_withdraw_fee_test.go @@ -6,7 +6,7 @@ import ( math "cosmossdk.io/math" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/fungible/types" ) @@ -93,10 +93,10 @@ func TestMsgUpdateZRC20WithdrawFee_ValidateBasic(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - require.ErrorIs(t, err, tt.err) + assert.ErrorIs(t, err, tt.err) return } - require.NoError(t, err) + assert.NoError(t, err) }) } } diff --git a/x/observer/genesis_test.go b/x/observer/genesis_test.go index 56cc00352f..853dc10996 100644 --- a/x/observer/genesis_test.go +++ b/x/observer/genesis_test.go @@ -3,7 +3,7 @@ package observer_test import ( "testing" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/nullify" "github.com/zeta-chain/zetacore/testutil/sample" @@ -47,10 +47,10 @@ func TestGenesis(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) observer.InitGenesis(ctx, *k, genesisState) got := observer.ExportGenesis(ctx, *k) - require.NotNil(t, got) + assert.NotNil(t, got) // Compare genesis after init and export nullify.Fill(&genesisState) nullify.Fill(got) - require.Equal(t, genesisState, *got) + assert.Equal(t, genesisState, *got) } diff --git a/x/observer/keeper/chain_nonces_test.go b/x/observer/keeper/chain_nonces_test.go index 0c511d3f79..44118ecc5b 100644 --- a/x/observer/keeper/chain_nonces_test.go +++ b/x/observer/keeper/chain_nonces_test.go @@ -3,7 +3,7 @@ package keeper_test import ( "testing" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" ) @@ -17,8 +17,8 @@ func TestKeeper_GetChainNonces(t *testing.T) { } for _, n := range chainNoncesList { rst, found := k.GetChainNonces(ctx, n.Index) - require.True(t, found) - require.Equal(t, n, rst) + assert.True(t, found) + assert.Equal(t, n, rst) } }) t.Run("Get chain nonces not found", func(t *testing.T) { @@ -28,7 +28,7 @@ func TestKeeper_GetChainNonces(t *testing.T) { k.SetChainNonces(ctx, n) } _, found := k.GetChainNonces(ctx, "not_found") - require.False(t, found) + assert.False(t, found) }) t.Run("Get all chain nonces", func(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) @@ -37,6 +37,6 @@ func TestKeeper_GetChainNonces(t *testing.T) { k.SetChainNonces(ctx, n) } rst := k.GetAllChainNonces(ctx) - require.Equal(t, chainNoncesList, rst) + assert.Equal(t, chainNoncesList, rst) }) } diff --git a/x/observer/keeper/chain_params_test.go b/x/observer/keeper/chain_params_test.go index c9142b7526..f5283c7feb 100644 --- a/x/observer/keeper/chain_params_test.go +++ b/x/observer/keeper/chain_params_test.go @@ -3,7 +3,7 @@ package keeper_test import ( "testing" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/common" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -15,11 +15,11 @@ func TestKeeper_GetSupportedChainFromChainID(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) // no core params list - require.Nil(t, k.GetSupportedChainFromChainID(ctx, getValidEthChainIDWithIndex(t, 0))) + assert.Nil(t, k.GetSupportedChainFromChainID(ctx, getValidEthChainIDWithIndex(t, 0))) // core params list but chain not in list setSupportedChain(ctx, *k, getValidEthChainIDWithIndex(t, 0)) - require.Nil(t, k.GetSupportedChainFromChainID(ctx, getValidEthChainIDWithIndex(t, 1))) + assert.Nil(t, k.GetSupportedChainFromChainID(ctx, getValidEthChainIDWithIndex(t, 1))) // chain params list but chain not supported chainParams := sample.ChainParams(getValidEthChainIDWithIndex(t, 0)) @@ -27,7 +27,7 @@ func TestKeeper_GetSupportedChainFromChainID(t *testing.T) { k.SetChainParamsList(ctx, types.ChainParamsList{ ChainParams: []*types.ChainParams{chainParams}, }) - require.Nil(t, k.GetSupportedChainFromChainID(ctx, getValidEthChainIDWithIndex(t, 0))) + assert.Nil(t, k.GetSupportedChainFromChainID(ctx, getValidEthChainIDWithIndex(t, 0))) }) t.Run("return chain if chain found", func(t *testing.T) { @@ -35,21 +35,21 @@ func TestKeeper_GetSupportedChainFromChainID(t *testing.T) { chainID := getValidEthChainIDWithIndex(t, 0) setSupportedChain(ctx, *k, getValidEthChainIDWithIndex(t, 1), chainID) chain := k.GetSupportedChainFromChainID(ctx, chainID) - require.NotNil(t, chain) - require.EqualValues(t, chainID, chain.ChainId) + assert.NotNil(t, chain) + assert.EqualValues(t, chainID, chain.ChainId) }) } func TestKeeper_GetSupportedChains(t *testing.T) { t.Run("return empty list if no core params list", func(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) - require.Empty(t, k.GetSupportedChains(ctx)) + assert.Empty(t, k.GetSupportedChains(ctx)) }) t.Run("return list containing supported chains", func(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) - require.Greater(t, len(common.ExternalChainList()), 5) + assert.Greater(t, len(common.ExternalChainList()), 5) supported1 := common.ExternalChainList()[0] supported2 := common.ExternalChainList()[1] unsupported := common.ExternalChainList()[2] @@ -69,10 +69,10 @@ func TestKeeper_GetSupportedChains(t *testing.T) { supportedChains := k.GetSupportedChains(ctx) - require.Len(t, supportedChains, 4) - require.EqualValues(t, supported1.ChainId, supportedChains[0].ChainId) - require.EqualValues(t, supported2.ChainId, supportedChains[1].ChainId) - require.EqualValues(t, supported3.ChainId, supportedChains[2].ChainId) - require.EqualValues(t, supported4.ChainId, supportedChains[3].ChainId) + assert.Len(t, supportedChains, 4) + assert.EqualValues(t, supported1.ChainId, supportedChains[0].ChainId) + assert.EqualValues(t, supported2.ChainId, supportedChains[1].ChainId) + assert.EqualValues(t, supported3.ChainId, supportedChains[2].ChainId) + assert.EqualValues(t, supported4.ChainId, supportedChains[3].ChainId) }) } diff --git a/x/observer/keeper/grpc_query_blame_test.go b/x/observer/keeper/grpc_query_blame_test.go index 8e66e3a2da..038a855305 100644 --- a/x/observer/keeper/grpc_query_blame_test.go +++ b/x/observer/keeper/grpc_query_blame_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/cosmos/cosmos-sdk/types/query" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/observer/types" @@ -26,8 +26,8 @@ func TestKeeper_BlameByIdentifier(t *testing.T) { }) blameRecords, found := k.GetBlame(ctx, index) - require.True(t, found) - require.Equal(t, index, blameRecords.Index) + assert.True(t, found) + assert.Equal(t, index, blameRecords.Index) } func TestKeeper_BlameByChainAndNonce(t *testing.T) { @@ -45,9 +45,9 @@ func TestKeeper_BlameByChainAndNonce(t *testing.T) { }) blameRecords, found := k.GetBlamesByChainAndNonce(ctx, chainId, int64(nonce)) - require.True(t, found) - require.Equal(t, 1, len(blameRecords)) - require.Equal(t, index, blameRecords[0].Index) + assert.True(t, found) + assert.Equal(t, 1, len(blameRecords)) + assert.Equal(t, index, blameRecords[0].Index) } func TestKeeper_BlameAll(t *testing.T) { @@ -61,12 +61,12 @@ func TestKeeper_BlameAll(t *testing.T) { return blameList[i].Index < blameList[j].Index }) rst, pageRes, err := k.GetAllBlamePaginated(ctx, &query.PageRequest{Limit: 10, CountTotal: true}) - require.NoError(t, err) + assert.NoError(t, err) sort.Slice(rst, func(i, j int) bool { return rst[i].Index < rst[j].Index }) - require.Equal(t, blameList, rst) - require.Equal(t, len(blameList), int(pageRes.Total)) + assert.Equal(t, blameList, rst) + assert.Equal(t, len(blameList), int(pageRes.Total)) }) t.Run("GetBlameRecord by offset ", func(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) @@ -79,13 +79,13 @@ func TestKeeper_BlameAll(t *testing.T) { return blameList[i].Index < blameList[j].Index }) rst, pageRes, err := k.GetAllBlamePaginated(ctx, &query.PageRequest{Offset: uint64(offset), CountTotal: true}) - require.NoError(t, err) + assert.NoError(t, err) sort.Slice(rst, func(i, j int) bool { return rst[i].Index < rst[j].Index }) - require.Subset(t, blameList, rst) - require.Equal(t, len(blameList)-offset, len(rst)) - require.Equal(t, len(blameList), int(pageRes.Total)) + assert.Subset(t, blameList, rst) + assert.Equal(t, len(blameList)-offset, len(rst)) + assert.Equal(t, len(blameList), int(pageRes.Total)) }) t.Run("GetAllBlameRecord", func(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) @@ -100,11 +100,11 @@ func TestKeeper_BlameAll(t *testing.T) { sort.Slice(blameList, func(i, j int) bool { return blameList[i].Index < blameList[j].Index }) - require.Equal(t, blameList, rst) + assert.Equal(t, blameList, rst) }) t.Run("Get no records if nothing is set", func(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) rst := k.GetAllBlame(ctx) - require.Len(t, rst, 0) + assert.Len(t, rst, 0) }) } diff --git a/x/observer/keeper/grpc_query_keygen_test.go b/x/observer/keeper/grpc_query_keygen_test.go index f4c61aeabd..27c90a0c3a 100644 --- a/x/observer/keeper/grpc_query_keygen_test.go +++ b/x/observer/keeper/grpc_query_keygen_test.go @@ -1,7 +1,7 @@ package keeper import ( - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "testing" @@ -29,9 +29,9 @@ func TestKeygenQuery(t *testing.T) { t.Run(tc.desc, func(t *testing.T) { response, err := keeper.Keygen(wctx, tc.request) if tc.err != nil { - require.ErrorIs(t, err, tc.err) + assert.ErrorIs(t, err, tc.err) } else { - require.Equal(t, tc.response, response) + assert.Equal(t, tc.response, response) } }) } diff --git a/x/observer/keeper/grpc_query_node_account_test.go b/x/observer/keeper/grpc_query_node_account_test.go index 37585214cf..3b36749b31 100644 --- a/x/observer/keeper/grpc_query_node_account_test.go +++ b/x/observer/keeper/grpc_query_node_account_test.go @@ -6,7 +6,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/x/observer/types" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -46,9 +45,9 @@ func TestNodeAccountQuerySingle(t *testing.T) { t.Run(tc.desc, func(t *testing.T) { response, err := keeper.NodeAccount(wctx, tc.request) if tc.err != nil { - require.ErrorIs(t, err, tc.err) + assert.ErrorIs(t, err, tc.err) } else { - require.Equal(t, tc.response, response) + assert.Equal(t, tc.response, response) } }) } @@ -73,7 +72,7 @@ func TestNodeAccountQueryPaginated(t *testing.T) { step := 2 for i := 0; i < len(msgs); i += step { resp, err := keeper.NodeAccountAll(wctx, request(nil, uint64(i), uint64(step), false)) - require.NoError(t, err) + assert.NoError(t, err) for j := i; j < len(msgs) && j < i+step; j++ { assert.Equal(t, &msgs[j], resp.NodeAccount[j-i]) } @@ -84,7 +83,7 @@ func TestNodeAccountQueryPaginated(t *testing.T) { var next []byte for i := 0; i < len(msgs); i += step { resp, err := keeper.NodeAccountAll(wctx, request(next, 0, uint64(step), false)) - require.NoError(t, err) + assert.NoError(t, err) for j := i; j < len(msgs) && j < i+step; j++ { assert.Equal(t, &msgs[j], resp.NodeAccount[j-i]) } @@ -93,11 +92,11 @@ func TestNodeAccountQueryPaginated(t *testing.T) { }) t.Run("Total", func(t *testing.T) { resp, err := keeper.NodeAccountAll(wctx, request(nil, 0, 0, true)) - require.NoError(t, err) - require.Equal(t, len(msgs), int(resp.Pagination.Total)) + assert.NoError(t, err) + assert.Equal(t, len(msgs), int(resp.Pagination.Total)) }) t.Run("InvalidRequest", func(t *testing.T) { _, err := keeper.NodeAccountAll(wctx, nil) - require.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) + assert.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) }) } diff --git a/x/observer/keeper/grpc_query_nonces_test.go b/x/observer/keeper/grpc_query_nonces_test.go index 584f237e7b..809220e4c7 100644 --- a/x/observer/keeper/grpc_query_nonces_test.go +++ b/x/observer/keeper/grpc_query_nonces_test.go @@ -6,7 +6,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/observer/types" @@ -51,9 +50,9 @@ func TestChainNoncesQuerySingle(t *testing.T) { t.Run(tc.desc, func(t *testing.T) { response, err := k.ChainNonces(wctx, tc.request) if tc.err != nil { - require.ErrorIs(t, err, tc.err) + assert.ErrorIs(t, err, tc.err) } else { - require.Equal(t, tc.response, response) + assert.Equal(t, tc.response, response) } }) } @@ -81,7 +80,7 @@ func TestChainNoncesQueryPaginated(t *testing.T) { step := 2 for i := 0; i < len(chainNonces); i += step { resp, err := k.ChainNoncesAll(wctx, request(nil, uint64(i), uint64(step), false)) - require.NoError(t, err) + assert.NoError(t, err) for j := i; j < len(chainNonces) && j < i+step; j++ { assert.Equal(t, chainNonces[j], resp.ChainNonces[j-i]) } @@ -92,7 +91,7 @@ func TestChainNoncesQueryPaginated(t *testing.T) { var next []byte for i := 0; i < len(chainNonces); i += step { resp, err := k.ChainNoncesAll(wctx, request(next, 0, uint64(step), false)) - require.NoError(t, err) + assert.NoError(t, err) for j := i; j < len(chainNonces) && j < i+step; j++ { assert.Equal(t, chainNonces[j], resp.ChainNonces[j-i]) } @@ -101,11 +100,11 @@ func TestChainNoncesQueryPaginated(t *testing.T) { }) t.Run("Total", func(t *testing.T) { resp, err := k.ChainNoncesAll(wctx, request(nil, 0, 0, true)) - require.NoError(t, err) - require.Equal(t, len(chainNonces), int(resp.Pagination.Total)) + assert.NoError(t, err) + assert.Equal(t, len(chainNonces), int(resp.Pagination.Total)) }) t.Run("InvalidRequest", func(t *testing.T) { _, err := k.ChainNoncesAll(wctx, nil) - require.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) + assert.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) }) } diff --git a/x/observer/keeper/grpc_query_params_test.go b/x/observer/keeper/grpc_query_params_test.go index 4cd534fa59..3eaf8963f0 100644 --- a/x/observer/keeper/grpc_query_params_test.go +++ b/x/observer/keeper/grpc_query_params_test.go @@ -4,7 +4,7 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/x/observer/types" ) @@ -15,6 +15,6 @@ func TestParamsQuery(t *testing.T) { keeper.SetParams(ctx, params) response, err := keeper.Params(wctx, &types.QueryParamsRequest{}) - require.NoError(t, err) - require.Equal(t, &types.QueryParamsResponse{Params: params}, response) + assert.NoError(t, err) + assert.Equal(t, &types.QueryParamsResponse{Params: params}, response) } diff --git a/x/observer/keeper/keeper_test.go b/x/observer/keeper/keeper_test.go index 7c13b7b0f2..41ad55a8d0 100644 --- a/x/observer/keeper/keeper_test.go +++ b/x/observer/keeper/keeper_test.go @@ -12,7 +12,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" typesparams "github.com/cosmos/cosmos-sdk/x/params/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmdb "github.com/tendermint/tm-db" "github.com/zeta-chain/zetacore/x/observer/types" @@ -26,7 +26,7 @@ func SetupKeeper(t testing.TB) (*Keeper, sdk.Context) { stateStore := store.NewCommitMultiStore(db) stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db) stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil) - require.NoError(t, stateStore.LoadLatestVersion()) + assert.NoError(t, stateStore.LoadLatestVersion()) registry := codectypes.NewInterfaceRegistry() cdc := codec.NewProtoCodec(registry) diff --git a/x/observer/keeper/msg_server_add_block_header_test.go b/x/observer/keeper/msg_server_add_block_header_test.go index 7f475bad4c..3d9f35b446 100644 --- a/x/observer/keeper/msg_server_add_block_header_test.go +++ b/x/observer/keeper/msg_server_add_block_header_test.go @@ -7,7 +7,6 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/ethereum/go-ethereum/rlp" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -37,7 +36,7 @@ func TestMsgServer_AddBlockHeader(t *testing.T) { IsEthTypeChainEnabled bool IsBtcTypeChainEnabled bool validator stakingtypes.Validator - wantErr require.ErrorAssertionFunc + wantErr assert.ErrorAssertionFunc }{ { name: "success submit eth header", @@ -51,7 +50,7 @@ func TestMsgServer_AddBlockHeader(t *testing.T) { IsEthTypeChainEnabled: true, IsBtcTypeChainEnabled: true, validator: validator, - wantErr: require.NoError, + wantErr: assert.NoError, }, { name: "failure submit eth header eth disabled", @@ -65,8 +64,8 @@ func TestMsgServer_AddBlockHeader(t *testing.T) { IsEthTypeChainEnabled: false, IsBtcTypeChainEnabled: true, validator: validator, - wantErr: func(t require.TestingT, err error, i ...interface{}) { - assert.ErrorIs(t, err, types.ErrBlockHeaderVerificationDisabled) + wantErr: func(t assert.TestingT, err error, i ...interface{}) bool { + return assert.ErrorIs(t, err, types.ErrBlockHeaderVerificationDisabled) }, }, { @@ -81,8 +80,8 @@ func TestMsgServer_AddBlockHeader(t *testing.T) { IsEthTypeChainEnabled: false, IsBtcTypeChainEnabled: true, validator: validator, - wantErr: func(t require.TestingT, err error, i ...interface{}) { - assert.ErrorIs(t, err, types.ErrNotAuthorizedPolicy) + wantErr: func(t assert.TestingT, err error, i ...interface{}) bool { + return assert.ErrorIs(t, err, types.ErrNotAuthorizedPolicy) }, }, { @@ -97,8 +96,8 @@ func TestMsgServer_AddBlockHeader(t *testing.T) { IsEthTypeChainEnabled: true, IsBtcTypeChainEnabled: true, validator: validator, - wantErr: func(t require.TestingT, err error, i ...interface{}) { - require.Error(t, err) + wantErr: func(t assert.TestingT, err error, i ...interface{}) bool { + return assert.Error(t, err) }, }, { @@ -113,7 +112,7 @@ func TestMsgServer_AddBlockHeader(t *testing.T) { IsEthTypeChainEnabled: true, IsBtcTypeChainEnabled: true, validator: validator, - wantErr: require.NoError, + wantErr: assert.NoError, }, { name: "should succeed to post 3rd header if 2nd header is posted", @@ -127,8 +126,8 @@ func TestMsgServer_AddBlockHeader(t *testing.T) { IsEthTypeChainEnabled: true, IsBtcTypeChainEnabled: true, validator: validator, - wantErr: func(t require.TestingT, err error, i ...interface{}) { - require.Error(t, err) + wantErr: func(t assert.TestingT, err error, i ...interface{}) bool { + return assert.Error(t, err) }, }, { @@ -143,8 +142,8 @@ func TestMsgServer_AddBlockHeader(t *testing.T) { IsEthTypeChainEnabled: true, IsBtcTypeChainEnabled: true, validator: validator, - wantErr: func(t require.TestingT, err error, i ...interface{}) { - require.ErrorIs(t, err, types.ErrSupportedChains) + wantErr: func(t assert.TestingT, err error, i ...interface{}) bool { + return assert.ErrorIs(t, err, types.ErrSupportedChains) }, }, } @@ -172,8 +171,8 @@ func TestMsgServer_AddBlockHeader(t *testing.T) { tc.wantErr(t, err) if err == nil { bhs, found := k.GetBlockHeaderState(ctx, tc.msg.ChainId) - require.True(t, found) - require.Equal(t, tc.msg.Height, bhs.LatestHeight) + assert.True(t, found) + assert.Equal(t, tc.msg.Height, bhs.LatestHeight) } }) } diff --git a/x/observer/keeper/msg_server_remove_chain_params_test.go b/x/observer/keeper/msg_server_remove_chain_params_test.go index d99b301403..15a089ab3f 100644 --- a/x/observer/keeper/msg_server_remove_chain_params_test.go +++ b/x/observer/keeper/msg_server_remove_chain_params_test.go @@ -4,7 +4,7 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/common" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -39,39 +39,39 @@ func TestMsgServer_RemoveChainParams(t *testing.T) { Creator: admin, ChainId: chain2, }) - require.NoError(t, err) + assert.NoError(t, err) // check list has two chain params chainParamsList, found := k.GetChainParamsList(ctx) - require.True(t, found) - require.Len(t, chainParamsList.ChainParams, 2) - require.Equal(t, chain1, chainParamsList.ChainParams[0].ChainId) - require.Equal(t, chain3, chainParamsList.ChainParams[1].ChainId) + assert.True(t, found) + assert.Len(t, chainParamsList.ChainParams, 2) + assert.Equal(t, chain1, chainParamsList.ChainParams[0].ChainId) + assert.Equal(t, chain3, chainParamsList.ChainParams[1].ChainId) // remove chain params _, err = srv.RemoveChainParams(sdk.WrapSDKContext(ctx), &types.MsgRemoveChainParams{ Creator: admin, ChainId: chain1, }) - require.NoError(t, err) + assert.NoError(t, err) // check list has one chain params chainParamsList, found = k.GetChainParamsList(ctx) - require.True(t, found) - require.Len(t, chainParamsList.ChainParams, 1) - require.Equal(t, chain3, chainParamsList.ChainParams[0].ChainId) + assert.True(t, found) + assert.Len(t, chainParamsList.ChainParams, 1) + assert.Equal(t, chain3, chainParamsList.ChainParams[0].ChainId) // remove chain params _, err = srv.RemoveChainParams(sdk.WrapSDKContext(ctx), &types.MsgRemoveChainParams{ Creator: admin, ChainId: chain3, }) - require.NoError(t, err) + assert.NoError(t, err) // check list has no chain params chainParamsList, found = k.GetChainParamsList(ctx) - require.True(t, found) - require.Len(t, chainParamsList.ChainParams, 0) + assert.True(t, found) + assert.Len(t, chainParamsList.ChainParams, 0) }) t.Run("cannot remove chain params if not authorized", func(t *testing.T) { @@ -82,7 +82,7 @@ func TestMsgServer_RemoveChainParams(t *testing.T) { Creator: sample.AccAddress(), ChainParams: sample.ChainParams(common.ExternalChainList()[0].ChainId), }) - require.ErrorIs(t, err, types.ErrNotAuthorizedPolicy) + assert.ErrorIs(t, err, types.ErrNotAuthorizedPolicy) // group 1 should not be able to update core params admin := sample.AccAddress() @@ -92,7 +92,7 @@ func TestMsgServer_RemoveChainParams(t *testing.T) { Creator: sample.AccAddress(), ChainParams: sample.ChainParams(common.ExternalChainList()[0].ChainId), }) - require.ErrorIs(t, err, types.ErrNotAuthorizedPolicy) + assert.ErrorIs(t, err, types.ErrNotAuthorizedPolicy) }) @@ -106,13 +106,13 @@ func TestMsgServer_RemoveChainParams(t *testing.T) { // not found if no chain params _, found := k.GetChainParamsList(ctx) - require.False(t, found) + assert.False(t, found) _, err := srv.RemoveChainParams(sdk.WrapSDKContext(ctx), &types.MsgRemoveChainParams{ Creator: admin, ChainId: common.ExternalChainList()[0].ChainId, }) - require.ErrorIs(t, err, types.ErrChainParamsNotFound) + assert.ErrorIs(t, err, types.ErrChainParamsNotFound) // add chain params k.SetChainParamsList(ctx, types.ChainParamsList{ @@ -128,6 +128,6 @@ func TestMsgServer_RemoveChainParams(t *testing.T) { Creator: admin, ChainId: common.ExternalChainList()[3].ChainId, }) - require.ErrorIs(t, err, types.ErrChainParamsNotFound) + assert.ErrorIs(t, err, types.ErrChainParamsNotFound) }) } diff --git a/x/observer/keeper/msg_server_update_chain_params_test.go b/x/observer/keeper/msg_server_update_chain_params_test.go index 7b2f8a5cb3..8d8680c919 100644 --- a/x/observer/keeper/msg_server_update_chain_params_test.go +++ b/x/observer/keeper/msg_server_update_chain_params_test.go @@ -4,7 +4,7 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/common" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -27,7 +27,7 @@ func TestMsgServer_UpdateChainParams(t *testing.T) { // check list initially empty _, found := k.GetChainParamsList(ctx) - require.False(t, found) + assert.False(t, found) // a new chain params can be added chainParams1 := sample.ChainParams(chain1) @@ -35,13 +35,13 @@ func TestMsgServer_UpdateChainParams(t *testing.T) { Creator: admin, ChainParams: chainParams1, }) - require.NoError(t, err) + assert.NoError(t, err) // check list has one chain params chainParamsList, found := k.GetChainParamsList(ctx) - require.True(t, found) - require.Len(t, chainParamsList.ChainParams, 1) - require.Equal(t, chainParams1, chainParamsList.ChainParams[0]) + assert.True(t, found) + assert.Len(t, chainParamsList.ChainParams, 1) + assert.Equal(t, chainParams1, chainParamsList.ChainParams[0]) // a new chian params can be added chainParams2 := sample.ChainParams(chain2) @@ -49,14 +49,14 @@ func TestMsgServer_UpdateChainParams(t *testing.T) { Creator: admin, ChainParams: chainParams2, }) - require.NoError(t, err) + assert.NoError(t, err) // check list has two chain params chainParamsList, found = k.GetChainParamsList(ctx) - require.True(t, found) - require.Len(t, chainParamsList.ChainParams, 2) - require.Equal(t, chainParams1, chainParamsList.ChainParams[0]) - require.Equal(t, chainParams2, chainParamsList.ChainParams[1]) + assert.True(t, found) + assert.Len(t, chainParamsList.ChainParams, 2) + assert.Equal(t, chainParams1, chainParamsList.ChainParams[0]) + assert.Equal(t, chainParams2, chainParamsList.ChainParams[1]) // a new chain params can be added chainParams3 := sample.ChainParams(chain3) @@ -64,15 +64,15 @@ func TestMsgServer_UpdateChainParams(t *testing.T) { Creator: admin, ChainParams: chainParams3, }) - require.NoError(t, err) + assert.NoError(t, err) // check list has three chain params chainParamsList, found = k.GetChainParamsList(ctx) - require.True(t, found) - require.Len(t, chainParamsList.ChainParams, 3) - require.Equal(t, chainParams1, chainParamsList.ChainParams[0]) - require.Equal(t, chainParams2, chainParamsList.ChainParams[1]) - require.Equal(t, chainParams3, chainParamsList.ChainParams[2]) + assert.True(t, found) + assert.Len(t, chainParamsList.ChainParams, 3) + assert.Equal(t, chainParams1, chainParamsList.ChainParams[0]) + assert.Equal(t, chainParams2, chainParamsList.ChainParams[1]) + assert.Equal(t, chainParams3, chainParamsList.ChainParams[2]) // chain params can be updated chainParams2.ConfirmationCount = chainParams2.ConfirmationCount + 1 @@ -80,15 +80,15 @@ func TestMsgServer_UpdateChainParams(t *testing.T) { Creator: admin, ChainParams: chainParams2, }) - require.NoError(t, err) + assert.NoError(t, err) // check list has three chain params chainParamsList, found = k.GetChainParamsList(ctx) - require.True(t, found) - require.Len(t, chainParamsList.ChainParams, 3) - require.Equal(t, chainParams1, chainParamsList.ChainParams[0]) - require.Equal(t, chainParams2, chainParamsList.ChainParams[1]) - require.Equal(t, chainParams3, chainParamsList.ChainParams[2]) + assert.True(t, found) + assert.Len(t, chainParamsList.ChainParams, 3) + assert.Equal(t, chainParams1, chainParamsList.ChainParams[0]) + assert.Equal(t, chainParams2, chainParamsList.ChainParams[1]) + assert.Equal(t, chainParams3, chainParamsList.ChainParams[2]) }) t.Run("cannot update chain params if not authorized", func(t *testing.T) { @@ -99,7 +99,7 @@ func TestMsgServer_UpdateChainParams(t *testing.T) { Creator: sample.AccAddress(), ChainParams: sample.ChainParams(common.ExternalChainList()[0].ChainId), }) - require.ErrorIs(t, err, types.ErrNotAuthorizedPolicy) + assert.ErrorIs(t, err, types.ErrNotAuthorizedPolicy) // group 1 should not be able to update chain params admin := sample.AccAddress() @@ -109,7 +109,7 @@ func TestMsgServer_UpdateChainParams(t *testing.T) { Creator: sample.AccAddress(), ChainParams: sample.ChainParams(common.ExternalChainList()[0].ChainId), }) - require.ErrorIs(t, err, types.ErrNotAuthorizedPolicy) + assert.ErrorIs(t, err, types.ErrNotAuthorizedPolicy) }) } diff --git a/x/observer/keeper/msg_server_update_crosschain_flags_test.go b/x/observer/keeper/msg_server_update_crosschain_flags_test.go index 555988694c..79654d6ed3 100644 --- a/x/observer/keeper/msg_server_update_crosschain_flags_test.go +++ b/x/observer/keeper/msg_server_update_crosschain_flags_test.go @@ -5,7 +5,7 @@ import ( "time" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/observer/keeper" @@ -46,17 +46,17 @@ func TestMsgServer_UpdateCrosschainFlags(t *testing.T) { IsBtcTypeChainEnabled: false, }, }) - require.NoError(t, err) + assert.NoError(t, err) flags, found := k.GetCrosschainFlags(ctx) - require.True(t, found) - require.False(t, flags.IsInboundEnabled) - require.False(t, flags.IsOutboundEnabled) - require.Equal(t, int64(42), flags.GasPriceIncreaseFlags.EpochLength) - require.Equal(t, time.Minute*42, flags.GasPriceIncreaseFlags.RetryInterval) - require.Equal(t, uint32(42), flags.GasPriceIncreaseFlags.GasPriceIncreasePercent) - require.True(t, flags.BlockHeaderVerificationFlags.IsEthTypeChainEnabled) - require.False(t, flags.BlockHeaderVerificationFlags.IsBtcTypeChainEnabled) + assert.True(t, found) + assert.False(t, flags.IsInboundEnabled) + assert.False(t, flags.IsOutboundEnabled) + assert.Equal(t, int64(42), flags.GasPriceIncreaseFlags.EpochLength) + assert.Equal(t, time.Minute*42, flags.GasPriceIncreaseFlags.RetryInterval) + assert.Equal(t, uint32(42), flags.GasPriceIncreaseFlags.GasPriceIncreasePercent) + assert.True(t, flags.BlockHeaderVerificationFlags.IsEthTypeChainEnabled) + assert.False(t, flags.BlockHeaderVerificationFlags.IsBtcTypeChainEnabled) setAdminCrossChainFlags(ctx, k, admin, types.Policy_Type_group2) @@ -75,17 +75,17 @@ func TestMsgServer_UpdateCrosschainFlags(t *testing.T) { IsBtcTypeChainEnabled: true, }, }) - require.NoError(t, err) + assert.NoError(t, err) flags, found = k.GetCrosschainFlags(ctx) - require.True(t, found) - require.True(t, flags.IsInboundEnabled) - require.True(t, flags.IsOutboundEnabled) - require.Equal(t, int64(43), flags.GasPriceIncreaseFlags.EpochLength) - require.Equal(t, time.Minute*43, flags.GasPriceIncreaseFlags.RetryInterval) - require.Equal(t, uint32(43), flags.GasPriceIncreaseFlags.GasPriceIncreasePercent) - require.False(t, flags.BlockHeaderVerificationFlags.IsEthTypeChainEnabled) - require.True(t, flags.BlockHeaderVerificationFlags.IsBtcTypeChainEnabled) + assert.True(t, found) + assert.True(t, flags.IsInboundEnabled) + assert.True(t, flags.IsOutboundEnabled) + assert.Equal(t, int64(43), flags.GasPriceIncreaseFlags.EpochLength) + assert.Equal(t, time.Minute*43, flags.GasPriceIncreaseFlags.RetryInterval) + assert.Equal(t, uint32(43), flags.GasPriceIncreaseFlags.GasPriceIncreasePercent) + assert.False(t, flags.BlockHeaderVerificationFlags.IsEthTypeChainEnabled) + assert.True(t, flags.BlockHeaderVerificationFlags.IsBtcTypeChainEnabled) // group 1 should be able to disable inbound and outbound setAdminCrossChainFlags(ctx, k, admin, types.Policy_Type_group1) @@ -96,17 +96,17 @@ func TestMsgServer_UpdateCrosschainFlags(t *testing.T) { IsInboundEnabled: false, IsOutboundEnabled: false, }) - require.NoError(t, err) + assert.NoError(t, err) flags, found = k.GetCrosschainFlags(ctx) - require.True(t, found) - require.False(t, flags.IsInboundEnabled) - require.False(t, flags.IsOutboundEnabled) - require.Equal(t, int64(43), flags.GasPriceIncreaseFlags.EpochLength) - require.Equal(t, time.Minute*43, flags.GasPriceIncreaseFlags.RetryInterval) - require.Equal(t, uint32(43), flags.GasPriceIncreaseFlags.GasPriceIncreasePercent) - require.False(t, flags.BlockHeaderVerificationFlags.IsEthTypeChainEnabled) - require.True(t, flags.BlockHeaderVerificationFlags.IsBtcTypeChainEnabled) + assert.True(t, found) + assert.False(t, flags.IsInboundEnabled) + assert.False(t, flags.IsOutboundEnabled) + assert.Equal(t, int64(43), flags.GasPriceIncreaseFlags.EpochLength) + assert.Equal(t, time.Minute*43, flags.GasPriceIncreaseFlags.RetryInterval) + assert.Equal(t, uint32(43), flags.GasPriceIncreaseFlags.GasPriceIncreasePercent) + assert.False(t, flags.BlockHeaderVerificationFlags.IsEthTypeChainEnabled) + assert.True(t, flags.BlockHeaderVerificationFlags.IsBtcTypeChainEnabled) // group 1 should be able to disable header verification setAdminCrossChainFlags(ctx, k, admin, types.Policy_Type_group1) @@ -121,22 +121,22 @@ func TestMsgServer_UpdateCrosschainFlags(t *testing.T) { IsBtcTypeChainEnabled: false, }, }) - require.NoError(t, err) + assert.NoError(t, err) flags, found = k.GetCrosschainFlags(ctx) - require.True(t, found) - require.False(t, flags.IsInboundEnabled) - require.False(t, flags.IsOutboundEnabled) - require.Equal(t, int64(43), flags.GasPriceIncreaseFlags.EpochLength) - require.Equal(t, time.Minute*43, flags.GasPriceIncreaseFlags.RetryInterval) - require.Equal(t, uint32(43), flags.GasPriceIncreaseFlags.GasPriceIncreasePercent) - require.False(t, flags.BlockHeaderVerificationFlags.IsEthTypeChainEnabled) - require.False(t, flags.BlockHeaderVerificationFlags.IsBtcTypeChainEnabled) + assert.True(t, found) + assert.False(t, flags.IsInboundEnabled) + assert.False(t, flags.IsOutboundEnabled) + assert.Equal(t, int64(43), flags.GasPriceIncreaseFlags.EpochLength) + assert.Equal(t, time.Minute*43, flags.GasPriceIncreaseFlags.RetryInterval) + assert.Equal(t, uint32(43), flags.GasPriceIncreaseFlags.GasPriceIncreasePercent) + assert.False(t, flags.BlockHeaderVerificationFlags.IsEthTypeChainEnabled) + assert.False(t, flags.BlockHeaderVerificationFlags.IsBtcTypeChainEnabled) // if flags are not defined, default should be used k.RemoveCrosschainFlags(ctx) _, found = k.GetCrosschainFlags(ctx) - require.False(t, found) + assert.False(t, found) setAdminCrossChainFlags(ctx, k, admin, types.Policy_Type_group2) @@ -145,15 +145,15 @@ func TestMsgServer_UpdateCrosschainFlags(t *testing.T) { IsInboundEnabled: false, IsOutboundEnabled: true, }) - require.NoError(t, err) + assert.NoError(t, err) flags, found = k.GetCrosschainFlags(ctx) - require.True(t, found) - require.False(t, flags.IsInboundEnabled) - require.True(t, flags.IsOutboundEnabled) - require.Equal(t, types.DefaultGasPriceIncreaseFlags.EpochLength, flags.GasPriceIncreaseFlags.EpochLength) - require.Equal(t, types.DefaultGasPriceIncreaseFlags.RetryInterval, flags.GasPriceIncreaseFlags.RetryInterval) - require.Equal(t, types.DefaultGasPriceIncreaseFlags.GasPriceIncreasePercent, flags.GasPriceIncreaseFlags.GasPriceIncreasePercent) + assert.True(t, found) + assert.False(t, flags.IsInboundEnabled) + assert.True(t, flags.IsOutboundEnabled) + assert.Equal(t, types.DefaultGasPriceIncreaseFlags.EpochLength, flags.GasPriceIncreaseFlags.EpochLength) + assert.Equal(t, types.DefaultGasPriceIncreaseFlags.RetryInterval, flags.GasPriceIncreaseFlags.RetryInterval) + assert.Equal(t, types.DefaultGasPriceIncreaseFlags.GasPriceIncreasePercent, flags.GasPriceIncreaseFlags.GasPriceIncreasePercent) }) t.Run("cannot update crosschain flags if not authorized", func(t *testing.T) { @@ -165,8 +165,8 @@ func TestMsgServer_UpdateCrosschainFlags(t *testing.T) { IsInboundEnabled: false, IsOutboundEnabled: false, }) - require.Error(t, err) - require.Equal(t, types.ErrNotAuthorizedPolicy, err) + assert.Error(t, err) + assert.Equal(t, types.ErrNotAuthorizedPolicy, err) admin := sample.AccAddress() setAdminCrossChainFlags(ctx, k, admin, types.Policy_Type_group1) @@ -176,7 +176,7 @@ func TestMsgServer_UpdateCrosschainFlags(t *testing.T) { IsInboundEnabled: false, IsOutboundEnabled: true, }) - require.Error(t, err) - require.Equal(t, types.ErrNotAuthorizedPolicy, err) + assert.Error(t, err) + assert.Equal(t, types.ErrNotAuthorizedPolicy, err) }) } diff --git a/x/observer/keeper/nonce_to_cctx_test.go b/x/observer/keeper/nonce_to_cctx_test.go index 1cbd023fbd..9fc65fcea2 100644 --- a/x/observer/keeper/nonce_to_cctx_test.go +++ b/x/observer/keeper/nonce_to_cctx_test.go @@ -3,7 +3,7 @@ package keeper_test import ( "testing" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" ) @@ -17,8 +17,8 @@ func TestKeeper_GetNonceToCctx(t *testing.T) { } for _, n := range nonceToCctxList { rst, found := k.GetNonceToCctx(ctx, n.Tss, n.ChainId, n.Nonce) - require.True(t, found) - require.Equal(t, n, rst) + assert.True(t, found) + assert.Equal(t, n, rst) } }) t.Run("Get nonce to cctx not found", func(t *testing.T) { @@ -28,7 +28,7 @@ func TestKeeper_GetNonceToCctx(t *testing.T) { k.SetNonceToCctx(ctx, n) } _, found := k.GetNonceToCctx(ctx, "not_found", 1, 1) - require.False(t, found) + assert.False(t, found) }) t.Run("Get all nonce to cctx", func(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) @@ -37,6 +37,6 @@ func TestKeeper_GetNonceToCctx(t *testing.T) { k.SetNonceToCctx(ctx, n) } rst := k.GetAllNonceToCctx(ctx) - require.Equal(t, nonceToCctxList, rst) + assert.Equal(t, nonceToCctxList, rst) }) } diff --git a/x/observer/keeper/params_test.go b/x/observer/keeper/params_test.go index 5ec4c260a3..744e8e6080 100644 --- a/x/observer/keeper/params_test.go +++ b/x/observer/keeper/params_test.go @@ -8,7 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/tendermint/tendermint/crypto" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/x/observer/types" ) @@ -18,7 +18,7 @@ func TestGetParams(t *testing.T) { k.SetParams(ctx, params) - require.EqualValues(t, params, k.GetParams(ctx)) + assert.EqualValues(t, params, k.GetParams(ctx)) } func TestGenerateAddress(t *testing.T) { diff --git a/x/observer/keeper/pending_nonces_test.go b/x/observer/keeper/pending_nonces_test.go index 0cb61f090d..5fa115fd30 100644 --- a/x/observer/keeper/pending_nonces_test.go +++ b/x/observer/keeper/pending_nonces_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/cosmos/cosmos-sdk/types/query" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" ) @@ -21,12 +21,12 @@ func TestKeeper_PendingNoncesAll(t *testing.T) { k.SetPendingNonces(ctx, nonce) } rst, pageRes, err := k.GetAllPendingNoncesPaginated(ctx, &query.PageRequest{Limit: 10, CountTotal: true}) - require.NoError(t, err) + assert.NoError(t, err) sort.SliceStable(rst, func(i, j int) bool { return rst[i].ChainId < rst[j].ChainId }) - require.Equal(t, nonces, rst) - require.Equal(t, len(nonces), int(pageRes.Total)) + assert.Equal(t, nonces, rst) + assert.Equal(t, len(nonces), int(pageRes.Total)) }) t.Run("Get all pending nonces paginated by offset", func(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) @@ -39,13 +39,13 @@ func TestKeeper_PendingNoncesAll(t *testing.T) { } offset := 10 rst, pageRes, err := k.GetAllPendingNoncesPaginated(ctx, &query.PageRequest{Offset: uint64(offset), CountTotal: true}) - require.NoError(t, err) + assert.NoError(t, err) sort.SliceStable(rst, func(i, j int) bool { return rst[i].ChainId < rst[j].ChainId }) - require.Subset(t, nonces, rst) - require.Len(t, rst, len(nonces)-offset) - require.Equal(t, len(nonces), int(pageRes.Total)) + assert.Subset(t, nonces, rst) + assert.Len(t, rst, len(nonces)-offset) + assert.Equal(t, len(nonces), int(pageRes.Total)) }) t.Run("Get all pending nonces ", func(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) @@ -57,10 +57,10 @@ func TestKeeper_PendingNoncesAll(t *testing.T) { k.SetPendingNonces(ctx, nonce) } rst, err := k.GetAllPendingNonces(ctx) - require.NoError(t, err) + assert.NoError(t, err) sort.SliceStable(rst, func(i, j int) bool { return rst[i].ChainId < rst[j].ChainId }) - require.Equal(t, nonces, rst) + assert.Equal(t, nonces, rst) }) } diff --git a/x/observer/keeper/tss_test.go b/x/observer/keeper/tss_test.go index 37099a519b..91994ed6f0 100644 --- a/x/observer/keeper/tss_test.go +++ b/x/observer/keeper/tss_test.go @@ -6,14 +6,13 @@ import ( "testing" "github.com/cosmos/cosmos-sdk/types/query" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/x/observer/types" ) @@ -61,9 +60,9 @@ func TestTSSQuerySingle(t *testing.T) { t.Run(tc.desc, func(t *testing.T) { response, err := k.TSS(wctx, tc.request) if tc.err != nil { - require.ErrorIs(t, err, tc.err) + assert.ErrorIs(t, err, tc.err) } else { - require.Equal(t, tc.response, response) + assert.Equal(t, tc.response, response) } }) } @@ -101,9 +100,9 @@ func TestTSSQueryHistory(t *testing.T) { request := &types.QueryTssHistoryRequest{} response, err := keeper.TssHistory(wctx, request) if tc.err != nil { - require.ErrorIs(t, err, tc.err) + assert.ErrorIs(t, err, tc.err) } else { - require.Equal(t, len(tssList), len(response.TssList)) + assert.Equal(t, len(tssList), len(response.TssList)) prevTss, found := keeper.GetPreviousTSS(ctx) assert.Equal(t, tc.foundPrevious, found) if found { @@ -122,15 +121,15 @@ func TestKeeper_TssHistory(t *testing.T) { k.SetTSSHistory(ctx, tss) } rst, pageRes, err := k.GetAllTSSPaginated(ctx, &query.PageRequest{Limit: 20, CountTotal: true}) - require.NoError(t, err) + assert.NoError(t, err) sort.Slice(tssList, func(i, j int) bool { return tssList[i].FinalizedZetaHeight < tssList[j].FinalizedZetaHeight }) sort.Slice(rst, func(i, j int) bool { return rst[i].FinalizedZetaHeight < rst[j].FinalizedZetaHeight }) - require.Equal(t, tssList, rst) - require.Equal(t, len(tssList), int(pageRes.Total)) + assert.Equal(t, tssList, rst) + assert.Equal(t, len(tssList), int(pageRes.Total)) }) t.Run("Get tss history paginated by offset", func(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) @@ -140,16 +139,16 @@ func TestKeeper_TssHistory(t *testing.T) { k.SetTSSHistory(ctx, tss) } rst, pageRes, err := k.GetAllTSSPaginated(ctx, &query.PageRequest{Offset: uint64(offset), CountTotal: true}) - require.NoError(t, err) + assert.NoError(t, err) sort.Slice(tssList, func(i, j int) bool { return tssList[i].FinalizedZetaHeight < tssList[j].FinalizedZetaHeight }) sort.Slice(rst, func(i, j int) bool { return rst[i].FinalizedZetaHeight < rst[j].FinalizedZetaHeight }) - require.Subset(t, tssList, rst) - require.Equal(t, len(tssList)-offset, len(rst)) - require.Equal(t, len(tssList), int(pageRes.Total)) + assert.Subset(t, tssList, rst) + assert.Equal(t, len(tssList)-offset, len(rst)) + assert.Equal(t, len(tssList), int(pageRes.Total)) }) t.Run("Get all TSS without pagination", func(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) @@ -164,7 +163,7 @@ func TestKeeper_TssHistory(t *testing.T) { sort.Slice(rst, func(i, j int) bool { return rst[i].FinalizedZetaHeight < rst[j].FinalizedZetaHeight }) - require.Equal(t, tssList, rst) + assert.Equal(t, tssList, rst) }) t.Run("Get historical TSS", func(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) @@ -174,7 +173,7 @@ func TestKeeper_TssHistory(t *testing.T) { } r := rand.Intn((len(tssList)-1)-0) + 0 tss, found := k.GetHistoricalTssByFinalizedHeight(ctx, tssList[r].FinalizedZetaHeight) - require.True(t, found) - require.Equal(t, tssList[r], tss) + assert.True(t, found) + assert.Equal(t, tssList[r], tss) }) } diff --git a/x/observer/keeper/utils_test.go b/x/observer/keeper/utils_test.go index e62cc57758..3e99956e71 100644 --- a/x/observer/keeper/utils_test.go +++ b/x/observer/keeper/utils_test.go @@ -8,7 +8,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" zetacommon "github.com/zeta-chain/zetacore/common" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -37,7 +36,7 @@ func getValidEthChainIDWithIndex(t *testing.T, index int) int64 { case 1: return zetacommon.GoerliChain().ChainId default: - require.Fail(t, "invalid index") + assert.Fail(t, "invalid index") } return 0 } diff --git a/x/observer/migrations/v3/migrate_test.go b/x/observer/migrations/v3/migrate_test.go index 604fd0a9c7..a2b3574bff 100644 --- a/x/observer/migrations/v3/migrate_test.go +++ b/x/observer/migrations/v3/migrate_test.go @@ -3,7 +3,7 @@ package v3_test import ( "testing" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" v3 "github.com/zeta-chain/zetacore/x/observer/migrations/v3" @@ -18,9 +18,9 @@ func TestMigrateStore(t *testing.T) { params.AdminPolicy = []*types.Admin_Policy{} k.SetParams(ctx, params) err := v3.MigrateStore(ctx, k) - require.NoError(t, err) + assert.NoError(t, err) params = k.GetParams(ctx) - require.Len(t, params.AdminPolicy, 0) + assert.Len(t, params.AdminPolicy, 0) // update admin policy admin := sample.AccAddress() @@ -41,11 +41,11 @@ func TestMigrateStore(t *testing.T) { } k.SetParams(ctx, params) err = v3.MigrateStore(ctx, k) - require.NoError(t, err) + assert.NoError(t, err) params = k.GetParams(ctx) - require.Len(t, params.AdminPolicy, 2) - require.Equal(t, params.AdminPolicy[0].PolicyType, types.Policy_Type_group1) - require.Equal(t, params.AdminPolicy[1].PolicyType, types.Policy_Type_group2) - require.Equal(t, params.AdminPolicy[0].Address, admin) - require.Equal(t, params.AdminPolicy[1].Address, admin) + assert.Len(t, params.AdminPolicy, 2) + assert.Equal(t, params.AdminPolicy[0].PolicyType, types.Policy_Type_group1) + assert.Equal(t, params.AdminPolicy[1].PolicyType, types.Policy_Type_group2) + assert.Equal(t, params.AdminPolicy[0].Address, admin) + assert.Equal(t, params.AdminPolicy[1].Address, admin) } diff --git a/x/observer/migrations/v5/migrate_test.go b/x/observer/migrations/v5/migrate_test.go index d97b3dde69..0ceebf9e03 100644 --- a/x/observer/migrations/v5/migrate_test.go +++ b/x/observer/migrations/v5/migrate_test.go @@ -6,7 +6,6 @@ import ( "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -59,13 +58,13 @@ func TestMigrateObserverParams(t *testing.T) { // set observer params dec42, err := sdk.NewDecFromStr("0.42") - require.NoError(t, err) + assert.NoError(t, err) dec43, err := sdk.NewDecFromStr("0.43") - require.NoError(t, err) + assert.NoError(t, err) dec1000, err := sdk.NewDecFromStr("1000.0") - require.NoError(t, err) + assert.NoError(t, err) dec1001, err := sdk.NewDecFromStr("1001.0") - require.NoError(t, err) + assert.NoError(t, err) params := types.Params{ ObserverParams: []*types.ObserverParams{ { @@ -86,23 +85,23 @@ func TestMigrateObserverParams(t *testing.T) { // perform migration err = v5.MigrateObserverParams(ctx, *k) - require.NoError(t, err) + assert.NoError(t, err) // check chain params newChainParamsList, found := k.GetChainParamsList(ctx) - require.True(t, found) + assert.True(t, found) // unchanged values - require.EqualValues(t, previousChainParamsList.ChainParams[0], newChainParamsList.ChainParams[0]) - require.EqualValues(t, previousChainParamsList.ChainParams[3], newChainParamsList.ChainParams[3]) + assert.EqualValues(t, previousChainParamsList.ChainParams[0], newChainParamsList.ChainParams[0]) + assert.EqualValues(t, previousChainParamsList.ChainParams[3], newChainParamsList.ChainParams[3]) // changed values - require.EqualValues(t, dec42, newChainParamsList.ChainParams[1].BallotThreshold) - require.EqualValues(t, dec1000, newChainParamsList.ChainParams[1].MinObserverDelegation) - require.EqualValues(t, dec43, newChainParamsList.ChainParams[2].BallotThreshold) - require.EqualValues(t, dec1001, newChainParamsList.ChainParams[2].MinObserverDelegation) - require.True(t, newChainParamsList.ChainParams[1].IsSupported) - require.True(t, newChainParamsList.ChainParams[2].IsSupported) + assert.EqualValues(t, dec42, newChainParamsList.ChainParams[1].BallotThreshold) + assert.EqualValues(t, dec1000, newChainParamsList.ChainParams[1].MinObserverDelegation) + assert.EqualValues(t, dec43, newChainParamsList.ChainParams[2].BallotThreshold) + assert.EqualValues(t, dec1001, newChainParamsList.ChainParams[2].MinObserverDelegation) + assert.True(t, newChainParamsList.ChainParams[1].IsSupported) + assert.True(t, newChainParamsList.ChainParams[2].IsSupported) // check remaining values are unchanged previousChainParamsList.ChainParams[1].BallotThreshold = dec42 @@ -111,6 +110,6 @@ func TestMigrateObserverParams(t *testing.T) { previousChainParamsList.ChainParams[2].MinObserverDelegation = dec1001 previousChainParamsList.ChainParams[1].IsSupported = true previousChainParamsList.ChainParams[2].IsSupported = true - require.EqualValues(t, previousChainParamsList.ChainParams[1], newChainParamsList.ChainParams[1]) - require.EqualValues(t, previousChainParamsList.ChainParams[2], newChainParamsList.ChainParams[2]) + assert.EqualValues(t, previousChainParamsList.ChainParams[1], newChainParamsList.ChainParams[1]) + assert.EqualValues(t, previousChainParamsList.ChainParams[2], newChainParamsList.ChainParams[2]) } diff --git a/x/observer/types/chain_params_test.go b/x/observer/types/chain_params_test.go index 0bdc9d814d..3d4d7ce456 100644 --- a/x/observer/types/chain_params_test.go +++ b/x/observer/types/chain_params_test.go @@ -3,7 +3,7 @@ package types_test import ( "testing" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" "github.com/zeta-chain/zetacore/x/observer/types" . "gopkg.in/check.v1" @@ -13,22 +13,22 @@ func TestChainParamsList_Validate(t *testing.T) { t.Run("should return no error for default list", func(t *testing.T) { list := types.GetDefaultChainParams() err := list.Validate() - require.NoError(t, err) + assert.NoError(t, err) }) t.Run("should return error for invalid chain id", func(t *testing.T) { list := types.GetDefaultChainParams() list.ChainParams[0].ChainId = 999 err := list.Validate() - require.Error(t, err) + assert.Error(t, err) }) t.Run("should return error for duplicated chain ID", func(t *testing.T) { list := types.GetDefaultChainParams() list.ChainParams = append(list.ChainParams, list.ChainParams[0]) err := list.Validate() - require.Error(t, err) - require.Contains(t, err.Error(), "duplicated chain id") + assert.Error(t, err) + assert.Contains(t, err.Error(), "duplicated chain id") }) } @@ -46,8 +46,8 @@ func TestUpdateChainParamsSuiteSuite(t *testing.T) { func TestChainParamsEqual(t *testing.T) { params := types.GetDefaultChainParams() - require.True(t, types.ChainParamsEqual(*params.ChainParams[0], *params.ChainParams[0])) - require.False(t, types.ChainParamsEqual(*params.ChainParams[0], *params.ChainParams[1])) + assert.True(t, types.ChainParamsEqual(*params.ChainParams[0], *params.ChainParams[0])) + assert.False(t, types.ChainParamsEqual(*params.ChainParams[0], *params.ChainParams[1])) } func (s *UpdateChainParamsSuite) SetupTest() { @@ -87,9 +87,9 @@ func (s *UpdateChainParamsSuite) SetupTest() { func (s *UpdateChainParamsSuite) TestValidParams() { err := types.ValidateChainParams(s.evmParams) - require.Nil(s.T(), err) + assert.Nil(s.T(), err) err = types.ValidateChainParams(s.btcParams) - require.Nil(s.T(), err) + assert.Nil(s.T(), err) } func (s *UpdateChainParamsSuite) TestCommonParams() { @@ -101,99 +101,99 @@ func (s *UpdateChainParamsSuite) TestBTCParams() { copy := *s.btcParams copy.WatchUtxoTicker = 0 err := types.ValidateChainParams(©) - require.NotNil(s.T(), err) + assert.NotNil(s.T(), err) } func (s *UpdateChainParamsSuite) TestCoreContractAddresses() { copy := *s.evmParams copy.ZetaTokenContractAddress = "0x123" err := types.ValidateChainParams(©) - require.NotNil(s.T(), err) + assert.NotNil(s.T(), err) copy = *s.evmParams copy.ZetaTokenContractAddress = "733aB8b06DDDEf27Eaa72294B0d7c9cEF7f12db9" err = types.ValidateChainParams(©) - require.NotNil(s.T(), err) + assert.NotNil(s.T(), err) copy = *s.evmParams copy.ConnectorContractAddress = "0x123" err = types.ValidateChainParams(©) - require.NotNil(s.T(), err) + assert.NotNil(s.T(), err) copy = *s.evmParams copy.ConnectorContractAddress = "733aB8b06DDDEf27Eaa72294B0d7c9cEF7f12db9" err = types.ValidateChainParams(©) - require.NotNil(s.T(), err) + assert.NotNil(s.T(), err) copy = *s.evmParams copy.Erc20CustodyContractAddress = "0x123" err = types.ValidateChainParams(©) - require.NotNil(s.T(), err) + assert.NotNil(s.T(), err) copy = *s.evmParams copy.Erc20CustodyContractAddress = "733aB8b06DDDEf27Eaa72294B0d7c9cEF7f12db9" err = types.ValidateChainParams(©) - require.NotNil(s.T(), err) + assert.NotNil(s.T(), err) } func (s *UpdateChainParamsSuite) Validate(params *types.ChainParams) { copy := *params copy.ConfirmationCount = 0 err := types.ValidateChainParams(©) - require.NotNil(s.T(), err) + assert.NotNil(s.T(), err) copy = *params copy.GasPriceTicker = 0 err = types.ValidateChainParams(©) - require.NotNil(s.T(), err) + assert.NotNil(s.T(), err) copy.GasPriceTicker = 300 err = types.ValidateChainParams(©) - require.Nil(s.T(), err) + assert.Nil(s.T(), err) copy.GasPriceTicker = 301 err = types.ValidateChainParams(©) - require.NotNil(s.T(), err) + assert.NotNil(s.T(), err) copy = *params copy.InTxTicker = 0 err = types.ValidateChainParams(©) - require.NotNil(s.T(), err) + assert.NotNil(s.T(), err) copy.InTxTicker = 300 err = types.ValidateChainParams(©) - require.Nil(s.T(), err) + assert.Nil(s.T(), err) copy.InTxTicker = 301 err = types.ValidateChainParams(©) - require.NotNil(s.T(), err) + assert.NotNil(s.T(), err) copy = *params copy.OutTxTicker = 0 err = types.ValidateChainParams(©) - require.NotNil(s.T(), err) + assert.NotNil(s.T(), err) copy.OutTxTicker = 300 err = types.ValidateChainParams(©) - require.Nil(s.T(), err) + assert.Nil(s.T(), err) copy.OutTxTicker = 301 err = types.ValidateChainParams(©) - require.NotNil(s.T(), err) + assert.NotNil(s.T(), err) copy = *params copy.OutboundTxScheduleInterval = 0 err = types.ValidateChainParams(©) - require.NotNil(s.T(), err) + assert.NotNil(s.T(), err) copy.OutboundTxScheduleInterval = 100 err = types.ValidateChainParams(©) - require.Nil(s.T(), err) + assert.Nil(s.T(), err) copy.OutboundTxScheduleInterval = 101 err = types.ValidateChainParams(©) - require.NotNil(s.T(), err) + assert.NotNil(s.T(), err) copy = *params copy.OutboundTxScheduleLookahead = 0 err = types.ValidateChainParams(©) - require.NotNil(s.T(), err) + assert.NotNil(s.T(), err) copy.OutboundTxScheduleLookahead = 500 err = types.ValidateChainParams(©) - require.Nil(s.T(), err) + assert.Nil(s.T(), err) copy.OutboundTxScheduleLookahead = 501 err = types.ValidateChainParams(©) - require.NotNil(s.T(), err) + assert.NotNil(s.T(), err) } diff --git a/x/observer/types/genesis_test.go b/x/observer/types/genesis_test.go index 1ba8212a35..d8ccb8414e 100644 --- a/x/observer/types/genesis_test.go +++ b/x/observer/types/genesis_test.go @@ -3,7 +3,7 @@ package types_test import ( "testing" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/x/observer/types" ) @@ -36,9 +36,9 @@ func TestGenesisState_Validate(t *testing.T) { t.Run(tc.desc, func(t *testing.T) { err := tc.genState.Validate() if tc.valid { - require.NoError(t, err) + assert.NoError(t, err) } else { - require.Error(t, err) + assert.Error(t, err) } }) } diff --git a/x/observer/types/message_add_observer_test.go b/x/observer/types/message_add_observer_test.go index b60ade5dc3..bdc723f759 100644 --- a/x/observer/types/message_add_observer_test.go +++ b/x/observer/types/message_add_observer_test.go @@ -4,7 +4,7 @@ import ( "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/observer/types" ) @@ -62,10 +62,10 @@ func TestMsgAddObserver_ValidateBasic(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - require.ErrorIs(t, err, tt.err) + assert.ErrorIs(t, err, tt.err) return } - require.NoError(t, err) + assert.NoError(t, err) }) } } diff --git a/x/observer/types/message_crosschain_flags.go b/x/observer/types/message_crosschain_flags.go index 58d49cd3d3..54f90e0efb 100644 --- a/x/observer/types/message_crosschain_flags.go +++ b/x/observer/types/message_crosschain_flags.go @@ -68,10 +68,10 @@ func (gpf GasPriceIncreaseFlags) Validate() error { return nil } -// GetRequiredGroup returns the required group policy for the message to execute the message +// GetRequiredGroup returns the assertd group policy for the message to execute the message // Group 1 should only be able to stop or disable functiunalities in case of emergency // this concerns disabling inbound and outbound txs or block header verification -// every other action requires group 2 +// every other action asserts group 2 func (msg *MsgUpdateCrosschainFlags) GetRequiredGroup() Policy_Type { if msg.IsInboundEnabled || msg.IsOutboundEnabled { return Policy_Type_group2 diff --git a/x/observer/types/message_crosschain_flags_test.go b/x/observer/types/message_crosschain_flags_test.go index 199b80c13a..ca2d75597f 100644 --- a/x/observer/types/message_crosschain_flags_test.go +++ b/x/observer/types/message_crosschain_flags_test.go @@ -4,7 +4,7 @@ import ( "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/observer/types" ) @@ -56,10 +56,10 @@ func TestMsgUpdateCrosschainFlags_ValidateBasic(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - require.ErrorIs(t, err, tt.err) + assert.ErrorIs(t, err, tt.err) return } - require.NoError(t, err) + assert.NoError(t, err) }) } } @@ -109,10 +109,10 @@ func TestGasPriceIncreaseFlags_Validate(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.gpf.Validate() if tt.errContains != "" { - require.ErrorContains(t, err, tt.errContains) + assert.ErrorContains(t, err, tt.errContains) return } - require.NoError(t, err) + assert.NoError(t, err) }) } } @@ -149,7 +149,7 @@ func TestMsgUpdateCrosschainFlags_GetRequiredGroup(t *testing.T) { want: types.Policy_Type_group1, }, { - name: "updating gas price increase flags requires group 2", + name: "updating gas price increase flags asserts group 2", msg: types.MsgUpdateCrosschainFlags{ Creator: sample.AccAddress(), IsInboundEnabled: false, @@ -168,7 +168,7 @@ func TestMsgUpdateCrosschainFlags_GetRequiredGroup(t *testing.T) { want: types.Policy_Type_group2, }, { - name: "enabling inbound requires group 2", + name: "enabling inbound asserts group 2", msg: types.MsgUpdateCrosschainFlags{ Creator: sample.AccAddress(), IsInboundEnabled: true, @@ -182,7 +182,7 @@ func TestMsgUpdateCrosschainFlags_GetRequiredGroup(t *testing.T) { want: types.Policy_Type_group2, }, { - name: "enabling outbound requires group 2", + name: "enabling outbound asserts group 2", msg: types.MsgUpdateCrosschainFlags{ Creator: sample.AccAddress(), IsInboundEnabled: false, @@ -196,7 +196,7 @@ func TestMsgUpdateCrosschainFlags_GetRequiredGroup(t *testing.T) { want: types.Policy_Type_group2, }, { - name: "enabling eth header verification requires group 2", + name: "enabling eth header verification asserts group 2", msg: types.MsgUpdateCrosschainFlags{ Creator: sample.AccAddress(), IsInboundEnabled: false, @@ -210,7 +210,7 @@ func TestMsgUpdateCrosschainFlags_GetRequiredGroup(t *testing.T) { want: types.Policy_Type_group2, }, { - name: "enabling btc header verification requires group 2", + name: "enabling btc header verification asserts group 2", msg: types.MsgUpdateCrosschainFlags{ Creator: sample.AccAddress(), IsInboundEnabled: false, @@ -227,7 +227,7 @@ func TestMsgUpdateCrosschainFlags_GetRequiredGroup(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - require.Equal(t, tt.want, tt.msg.GetRequiredGroup()) + assert.Equal(t, tt.want, tt.msg.GetRequiredGroup()) }) } } diff --git a/x/observer/types/message_remove_chain_params_test.go b/x/observer/types/message_remove_chain_params_test.go index 10d5a4c777..acc20ca9dd 100644 --- a/x/observer/types/message_remove_chain_params_test.go +++ b/x/observer/types/message_remove_chain_params_test.go @@ -4,7 +4,7 @@ import ( "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/common" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/observer/types" @@ -45,10 +45,10 @@ func TestMsgRemoveChainParams_ValidateBasic(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - require.ErrorIs(t, err, tt.err) + assert.ErrorIs(t, err, tt.err) return } - require.NoError(t, err) + assert.NoError(t, err) }) } } diff --git a/x/observer/types/message_set_ballot_threshold_test.go b/x/observer/types/message_set_ballot_threshold_test.go index 6e797800c1..814dfd5646 100644 --- a/x/observer/types/message_set_ballot_threshold_test.go +++ b/x/observer/types/message_set_ballot_threshold_test.go @@ -25,10 +25,10 @@ package types // t.Run(tt.name, func(t *testing.T) { // err := tt.msg.ValidateBasic() // if tt.err != nil { -// require.ErrorIs(t, err, tt.err) +// assert.ErrorIs(t, err, tt.err) // return // } -// require.NoError(t, err) +// assert.NoError(t, err) // }) // } //} diff --git a/x/observer/types/message_update_chain_params_test.go b/x/observer/types/message_update_chain_params_test.go index 3f3efc4e2f..5c979dda08 100644 --- a/x/observer/types/message_update_chain_params_test.go +++ b/x/observer/types/message_update_chain_params_test.go @@ -4,7 +4,7 @@ import ( "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/common" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/observer/types" @@ -44,10 +44,10 @@ func TestMsgUpdateChainParams_ValidateBasic(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - require.ErrorIs(t, err, tt.err) + assert.ErrorIs(t, err, tt.err) return } - require.NoError(t, err) + assert.NoError(t, err) }) } } diff --git a/x/observer/types/message_update_keygen_test.go b/x/observer/types/message_update_keygen_test.go index b7ad69741c..13213b9a98 100644 --- a/x/observer/types/message_update_keygen_test.go +++ b/x/observer/types/message_update_keygen_test.go @@ -4,7 +4,7 @@ import ( "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/observer/types" ) @@ -32,10 +32,10 @@ func TestMsgUpdateKeygen_ValidateBasic(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - require.ErrorIs(t, err, tt.err) + assert.ErrorIs(t, err, tt.err) return } - require.NoError(t, err) + assert.NoError(t, err) }) } } diff --git a/x/observer/types/message_update_observer_test.go b/x/observer/types/message_update_observer_test.go index 0cff6bd25b..e438f6d9db 100644 --- a/x/observer/types/message_update_observer_test.go +++ b/x/observer/types/message_update_observer_test.go @@ -4,7 +4,7 @@ import ( "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/observer/types" ) @@ -79,10 +79,10 @@ func TestNewMsgUpdateObserver(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - require.ErrorIs(t, err, tt.err) + assert.ErrorIs(t, err, tt.err) return } - require.NoError(t, err) + assert.NoError(t, err) }) } } From bcfe94f17beb30988df7d553dc7fc9e6d020c2da Mon Sep 17 00:00:00 2001 From: Tanmay Date: Fri, 2 Feb 2024 14:15:40 -0500 Subject: [PATCH 06/13] use assert in app directory --- app/ante/ante_test.go | 4 ++-- app/ante/vesting_test.go | 10 +++++----- .../keeper/msg_server_add_to_outtx_tracker_test.go | 10 +++------- x/crosschain/keeper/msg_server_vote_inbound_tx.go | 2 +- x/crosschain/keeper/msg_server_vote_outbound_tx.go | 2 +- .../keeper/msg_server_update_zrc20_paused_status.go | 6 +++--- x/observer/types/message_crosschain_flags.go | 4 ++-- 7 files changed, 17 insertions(+), 21 deletions(-) diff --git a/app/ante/ante_test.go b/app/ante/ante_test.go index 146e50c6ae..f5c8bc53f4 100644 --- a/app/ante/ante_test.go +++ b/app/ante/ante_test.go @@ -7,7 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/authz" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/app" "github.com/zeta-chain/zetacore/app/ante" "github.com/zeta-chain/zetacore/testutil/sample" @@ -226,7 +226,7 @@ func TestIsSystemTx(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { is := ante.IsSystemTx(tt.tx, tt.isAuthorized) - require.Equal(t, tt.wantIs, is) + assert.Equal(t, tt.wantIs, is) }) } } diff --git a/app/ante/vesting_test.go b/app/ante/vesting_test.go index fac1cb16d5..3310b55b3b 100644 --- a/app/ante/vesting_test.go +++ b/app/ante/vesting_test.go @@ -9,7 +9,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" vesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/app" "github.com/zeta-chain/zetacore/app/ante" @@ -86,7 +86,7 @@ func TestVesting_AnteHandle(t *testing.T) { []uint64{0}, testPrivKey, ) - require.NoError(t, err) + assert.NoError(t, err) mmd := MockAnteHandler{} ctx := sdk.Context{}.WithIsCheckTx(true) @@ -94,10 +94,10 @@ func TestVesting_AnteHandle(t *testing.T) { _, err = decorator.AnteHandle(ctx, tx, false, mmd.AnteHandle) if tt.wantHasErr { - require.Error(t, err) - require.Contains(t, err.Error(), tt.wantErr) + assert.Error(t, err) + assert.Contains(t, err.Error(), tt.wantErr) } else { - require.NoError(t, err) + assert.NoError(t, err) } }) } diff --git a/x/crosschain/keeper/msg_server_add_to_outtx_tracker_test.go b/x/crosschain/keeper/msg_server_add_to_outtx_tracker_test.go index 546650d61a..7a39d34579 100644 --- a/x/crosschain/keeper/msg_server_add_to_outtx_tracker_test.go +++ b/x/crosschain/keeper/msg_server_add_to_outtx_tracker_test.go @@ -1,6 +1,3 @@ -//go:build TESTNET -// +build TESTNET - package keeper_test import ( @@ -14,7 +11,6 @@ import ( "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/crosschain/keeper" "github.com/zeta-chain/zetacore/x/crosschain/types" - observerTypes "github.com/zeta-chain/zetacore/x/observer/types" observertypes "github.com/zeta-chain/zetacore/x/observer/types" ) @@ -279,10 +275,10 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { func setupTssAndNonceToCctx(k *keeper.Keeper, ctx sdk.Context, chainId, nonce int64) { tssPubKey := "zetapub1addwnpepq28c57cvcs0a2htsem5zxr6qnlvq9mzhmm76z3jncsnzz32rclangr2g35p" - k.GetObserverKeeper().SetTSS(ctx, observerTypes.TSS{ + k.GetObserverKeeper().SetTSS(ctx, observertypes.TSS{ TssPubkey: tssPubKey, }) - k.SetPendingNonces(ctx, types.PendingNonces{ + k.GetObserverKeeper().SetPendingNonces(ctx, observertypes.PendingNonces{ Tss: tssPubKey, NonceLow: 0, NonceHigh: 1, @@ -296,7 +292,7 @@ func setupTssAndNonceToCctx(k *keeper.Keeper, ctx sdk.Context, chainId, nonce in }, } k.SetCrossChainTx(ctx, cctx) - k.SetNonceToCctx(ctx, types.NonceToCctx{ + k.GetObserverKeeper().SetNonceToCctx(ctx, observertypes.NonceToCctx{ ChainId: chainId, Nonce: nonce, CctxIndex: "0x123", diff --git a/x/crosschain/keeper/msg_server_vote_inbound_tx.go b/x/crosschain/keeper/msg_server_vote_inbound_tx.go index 3b4034c485..57c3e54041 100644 --- a/x/crosschain/keeper/msg_server_vote_inbound_tx.go +++ b/x/crosschain/keeper/msg_server_vote_inbound_tx.go @@ -32,7 +32,7 @@ import ( // // If the receiver chain is a connected chain, the `FinalizeInbound` method is // called to prepare the CCTX to be processed as an outbound transaction. To -// cover the outbound transaction fee, the assertd amount of tokens submitted +// cover the outbound transaction fee, the required amount of tokens submitted // with the CCTX are swapped using a Uniswap V2 contract instance on ZetaChain // for the ZRC20 of the gas token of the receiver chain. The ZRC20 tokens are // then burned. The nonce is updated. If everything is successful, the CCTX diff --git a/x/crosschain/keeper/msg_server_vote_outbound_tx.go b/x/crosschain/keeper/msg_server_vote_outbound_tx.go index 30af53fdcc..17319d1f8a 100644 --- a/x/crosschain/keeper/msg_server_vote_outbound_tx.go +++ b/x/crosschain/keeper/msg_server_vote_outbound_tx.go @@ -31,7 +31,7 @@ import ( // status. // // If the previous status was `PendingOutbound`, a new revert transaction is -// created. To cover the revert transaction fee, the assertd amount of tokens +// created. To cover the revert transaction fee, the required amount of tokens // submitted with the CCTX are swapped using a Uniswap V2 contract instance on // ZetaChain for the ZRC20 of the gas token of the receiver chain. The ZRC20 // tokens are then diff --git a/x/fungible/keeper/msg_server_update_zrc20_paused_status.go b/x/fungible/keeper/msg_server_update_zrc20_paused_status.go index 3fe9380f2f..8605678cf9 100644 --- a/x/fungible/keeper/msg_server_update_zrc20_paused_status.go +++ b/x/fungible/keeper/msg_server_update_zrc20_paused_status.go @@ -28,11 +28,11 @@ func (k msgServer) UpdateZRC20PausedStatus( // check if the sender is the admin // unpausing asserts group2 admin - assertPolicyAccount := zetaObserverTypes.Policy_Type_group1 + requiredPolicyAccount := zetaObserverTypes.Policy_Type_group1 if msg.Action == types.UpdatePausedStatusAction_UNPAUSE { - assertPolicyAccount = zetaObserverTypes.Policy_Type_group2 + requiredPolicyAccount = zetaObserverTypes.Policy_Type_group2 } - if msg.Creator != k.observerKeeper.GetParams(ctx).GetAdminPolicyAccount(assertPolicyAccount) { + if msg.Creator != k.observerKeeper.GetParams(ctx).GetAdminPolicyAccount(requiredPolicyAccount) { return nil, cosmoserrors.Wrap(sdkerrors.ErrUnauthorized, "Update can only be executed by the correct policy account") } diff --git a/x/observer/types/message_crosschain_flags.go b/x/observer/types/message_crosschain_flags.go index 54f90e0efb..58d49cd3d3 100644 --- a/x/observer/types/message_crosschain_flags.go +++ b/x/observer/types/message_crosschain_flags.go @@ -68,10 +68,10 @@ func (gpf GasPriceIncreaseFlags) Validate() error { return nil } -// GetRequiredGroup returns the assertd group policy for the message to execute the message +// GetRequiredGroup returns the required group policy for the message to execute the message // Group 1 should only be able to stop or disable functiunalities in case of emergency // this concerns disabling inbound and outbound txs or block header verification -// every other action asserts group 2 +// every other action requires group 2 func (msg *MsgUpdateCrosschainFlags) GetRequiredGroup() Policy_Type { if msg.IsInboundEnabled || msg.IsOutboundEnabled { return Policy_Type_group2 From 03787365ee563112165eed7775014dc61541ca1f Mon Sep 17 00:00:00 2001 From: Tanmay Date: Fri, 2 Feb 2024 14:28:21 -0500 Subject: [PATCH 07/13] use assert in zetaclient directory --- cmd/zetacored/flags_test.go | 8 +- common/address_test.go | 16 +- common/chain_id_test.go | 8 +- common/chain_test.go | 16 +- common/headers_test.go | 54 +++--- common/proof_test.go | 42 ++--- .../smoketest/contracts/testdapp/TestDApp.sol | 4 +- .../smoketest/contracts/vault/Vault.sol | 10 +- rpc/ethereum/pubsub/pubsub_test.go | 22 +-- rpc/types/block_test.go | 30 ++-- rpc/types/events_test.go | 18 +- server/config/config_test.go | 8 +- zetaclient/btc_signer_test.go | 161 +++++++++--------- zetaclient/hsm/hsm_signer_test.go | 16 +- zetaclient/utils_test.go | 6 +- 15 files changed, 209 insertions(+), 210 deletions(-) diff --git a/cmd/zetacored/flags_test.go b/cmd/zetacored/flags_test.go index 1fbdc4d4d0..993b9181f2 100644 --- a/cmd/zetacored/flags_test.go +++ b/cmd/zetacored/flags_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/spf13/cobra" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" zetacore "github.com/zeta-chain/zetacore/cmd/zetacored" ) @@ -78,14 +78,14 @@ func TestReplaceFlag(t *testing.T) { err := zetacore.ReplaceFlag(tt.cmd, tt.subCommand, tt.flagName, tt.newDefaultValue) if tt.wantErr { - require.Error(t, err) + assert.Error(t, err) } else { - require.NoError(t, err) + assert.NoError(t, err) // Check if the value was replaced correctly c, _, _ := tt.cmd.Find(tt.subCommand) f := c.Flags().Lookup(tt.flagName) - require.Equal(t, tt.expectedValue, f.DefValue) + assert.Equal(t, tt.expectedValue, f.DefValue) } }) } diff --git a/common/address_test.go b/common/address_test.go index af386c3bdc..3e8ec1beba 100644 --- a/common/address_test.go +++ b/common/address_test.go @@ -3,7 +3,7 @@ package common import ( "testing" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" . "gopkg.in/check.v1" ) @@ -12,31 +12,31 @@ func TestPackage(t *testing.T) { TestingT(t) } func TestAddress(t *testing.T) { addr := NewAddress("bnb1lejrrtta9cgr49fuh7ktu3sddhe0ff7wenlpn6") - require.EqualValuesf(t, NoAddress, addr, "address string should be empty") + assert.EqualValuesf(t, NoAddress, addr, "address string should be empty") addr = NewAddress("bogus") - require.EqualValuesf(t, NoAddress, addr, "address string should be empty") + assert.EqualValuesf(t, NoAddress, addr, "address string should be empty") addr = NewAddress("0x90f2b1ae50e6018230e90a33f98c7844a0ab635a") - require.EqualValuesf(t, "0x90f2b1ae50e6018230e90a33f98c7844a0ab635a", addr.String(), "address string should be equal") + assert.EqualValuesf(t, "0x90f2b1ae50e6018230e90a33f98c7844a0ab635a", addr.String(), "address string should be equal") } func TestDecodeBtcAddress(t *testing.T) { t.Run("invalid string", func(t *testing.T) { _, err := DecodeBtcAddress("�U�ڷ���i߭����꿚�l", 18332) - require.ErrorContains(t, err, "runtime error: index out of range") + assert.ErrorContains(t, err, "runtime error: index out of range") }) t.Run("invalid chain", func(t *testing.T) { _, err := DecodeBtcAddress("14CEjTd5ci3228J45GdnGeUKLSSeCWUQxK", 0) - require.ErrorContains(t, err, "is not a Bitcoin chain") + assert.ErrorContains(t, err, "is not a Bitcoin chain") }) t.Run("nil pointer dereference", func(t *testing.T) { _, err := DecodeBtcAddress("tb1qy9pqmk2pd9sv63g27jt8r657wy0d9uee4x2dt2", 18332) - require.ErrorContains(t, err, "runtime error: invalid memory address or nil pointer dereference") + assert.ErrorContains(t, err, "runtime error: invalid memory address or nil pointer dereference") }) t.Run("valid address", func(t *testing.T) { _, err := DecodeBtcAddress("bcrt1qy9pqmk2pd9sv63g27jt8r657wy0d9uee4x2dt2", 18444) - require.NoError(t, err) + assert.NoError(t, err) }) } diff --git a/common/chain_id_test.go b/common/chain_id_test.go index cd4a18ca18..5b01d43bd9 100644 --- a/common/chain_id_test.go +++ b/common/chain_id_test.go @@ -3,7 +3,7 @@ package common_test import ( "testing" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/common" ) @@ -48,10 +48,10 @@ func TestCosmosToEthChainID(t *testing.T) { t.Run(tc.name, func(t *testing.T) { ethChainID, err := common.CosmosToEthChainID(tc.chainID) if tc.isErr { - require.Error(t, err) + assert.Error(t, err) } else { - require.NoError(t, err) - require.Equal(t, tc.expected, ethChainID) + assert.NoError(t, err) + assert.Equal(t, tc.expected, ethChainID) } }) } diff --git a/common/chain_test.go b/common/chain_test.go index f0e3c1ceed..cc5795b499 100644 --- a/common/chain_test.go +++ b/common/chain_test.go @@ -3,7 +3,7 @@ package common import ( "testing" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" ) func TestChain_EncodeAddress(t *testing.T) { @@ -41,18 +41,18 @@ func TestChain_EncodeAddress(t *testing.T) { t.Run(tc.name, func(t *testing.T) { s, err := tc.chain.EncodeAddress(tc.b) if tc.wantErr { - require.Error(t, err) + assert.Error(t, err) return } - require.Equal(t, tc.want, s) + assert.Equal(t, tc.want, s) }) } } func TestChain_InChainList(t *testing.T) { - require.True(t, ZetaChainMainnet().InChainList(ZetaChainList())) - require.True(t, ZetaMocknetChain().InChainList(ZetaChainList())) - require.True(t, ZetaPrivnetChain().InChainList(ZetaChainList())) - require.True(t, ZetaTestnetChain().InChainList(ZetaChainList())) - require.False(t, EthChain().InChainList(ZetaChainList())) + assert.True(t, ZetaChainMainnet().InChainList(ZetaChainList())) + assert.True(t, ZetaMocknetChain().InChainList(ZetaChainList())) + assert.True(t, ZetaPrivnetChain().InChainList(ZetaChainList())) + assert.True(t, ZetaTestnetChain().InChainList(ZetaChainList())) + assert.False(t, EthChain().InChainList(ZetaChainList())) } diff --git a/common/headers_test.go b/common/headers_test.go index 2a0ed6bb74..9c9af29a30 100644 --- a/common/headers_test.go +++ b/common/headers_test.go @@ -17,7 +17,7 @@ import ( "github.com/btcsuite/btcd/wire" ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/ethclient" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/common" ) @@ -36,20 +36,20 @@ func TestTrueEthereumHeader(t *testing.T) { var header ethtypes.Header // read file into a byte slice file, err := os.Open("./test_data/eth_header_18495266.json") - require.NoError(t, err) + assert.NoError(t, err) defer file.Close() headerBytes := make([]byte, 4096) n, err := file.Read(headerBytes) - require.NoError(t, err) + assert.NoError(t, err) err = header.UnmarshalJSON(headerBytes[:n]) - require.NoError(t, err) + assert.NoError(t, err) var buffer bytes.Buffer err = header.EncodeRLP(&buffer) - require.NoError(t, err) + assert.NoError(t, err) headerData := common.NewEthereumHeader(buffer.Bytes()) err = headerData.Validate(header.Hash().Bytes(), 1, 18495266) - require.NoError(t, err) + assert.NoError(t, err) } func TestFalseEthereumHeader(t *testing.T) { @@ -57,22 +57,22 @@ func TestFalseEthereumHeader(t *testing.T) { var header ethtypes.Header // read file into a byte slice file, err := os.Open("./test_data/eth_header_18495266.json") - require.NoError(t, err) + assert.NoError(t, err) defer file.Close() headerBytes := make([]byte, 4096) n, err := file.Read(headerBytes) - require.NoError(t, err) + assert.NoError(t, err) err = header.UnmarshalJSON(headerBytes[:n]) - require.NoError(t, err) + assert.NoError(t, err) hash := header.Hash() header.Number = big.NewInt(18495267) var buffer bytes.Buffer err = header.EncodeRLP(&buffer) - require.NoError(t, err) + assert.NoError(t, err) headerData := common.NewEthereumHeader(buffer.Bytes()) err = headerData.Validate(hash.Bytes(), 1, 18495267) - require.Error(t, err) + assert.Error(t, err) } func TestTrueBitcoinHeader(t *testing.T) { @@ -81,7 +81,7 @@ func TestTrueBitcoinHeader(t *testing.T) { for _, b := range blocks.Blocks { // Deserialize the header bytes from base64 headerBytes, err := base64.StdEncoding.DecodeString(b.HeaderBase64) - require.NoError(t, err) + assert.NoError(t, err) header := unmarshalHeader(t, headerBytes) // Validate @@ -95,7 +95,7 @@ func TestFakeBitcoinHeader(t *testing.T) { for _, b := range blocks.Blocks { // Deserialize the header bytes from base64 headerBytes, err := base64.StdEncoding.DecodeString(b.HeaderBase64) - require.NoError(t, err) + assert.NoError(t, err) header := unmarshalHeader(t, headerBytes) // Validate @@ -106,16 +106,16 @@ func TestFakeBitcoinHeader(t *testing.T) { func BitcoinHeaderValidationLiveTest(t *testing.T) { client := createBTCClient(t) bn, err := client.GetBlockCount() - require.NoError(t, err) + assert.NoError(t, err) fmt.Printf("Verifying block headers in block range [%d, %d]\n", bn-numHeadersToTest+1, bn) for height := bn - numHeadersToTest + 1; height <= bn; height++ { blockHash, err := client.GetBlockHash(height) - require.NoError(t, err) + assert.NoError(t, err) // Get the block header header, err := client.GetBlockHeader(blockHash) - require.NoError(t, err) + assert.NoError(t, err) headerBytes := marshalHeader(t, header) // Validate true header @@ -138,7 +138,7 @@ func createBTCClient(t *testing.T) *rpcclient.Client { Params: "testnet3", } client, err := rpcclient.New(connCfg, nil) - require.NoError(t, err) + assert.NoError(t, err) return client } @@ -160,14 +160,14 @@ func copyHeader(header *wire.BlockHeader) *wire.BlockHeader { func marshalHeader(t *testing.T, header *wire.BlockHeader) []byte { var headerBuf bytes.Buffer err := header.Serialize(&headerBuf) - require.NoError(t, err) + assert.NoError(t, err) return headerBuf.Bytes() } func unmarshalHeader(t *testing.T, headerBytes []byte) *wire.BlockHeader { var header wire.BlockHeader err := header.Deserialize(bytes.NewReader(headerBytes)) - require.NoError(t, err) + assert.NoError(t, err) return &header } @@ -176,11 +176,11 @@ func validateTrueBitcoinHeader(t *testing.T, header *wire.BlockHeader, headerByt // True Bitcoin header should pass validation err := common.ValidateBitcoinHeader(headerBytes, blockHash[:], 18332) - require.NoError(t, err) + assert.NoError(t, err) // True Bitcoin header should pass timestamp validation err = common.NewBitcoinHeader(headerBytes).ValidateTimestamp(time.Now()) - require.NoError(t, err) + assert.NoError(t, err) } func validateFakeBitcoinHeader(t *testing.T, header *wire.BlockHeader, headerBytes []byte) { @@ -188,7 +188,7 @@ func validateFakeBitcoinHeader(t *testing.T, header *wire.BlockHeader, headerByt // Incorrect header length should fail validation err := common.ValidateBitcoinHeader(headerBytes[:79], blockHash[:], 18332) - require.Error(t, err) + assert.Error(t, err) // Incorrect version should fail validation fakeHeader := copyHeader(header) @@ -196,7 +196,7 @@ func validateFakeBitcoinHeader(t *testing.T, header *wire.BlockHeader, headerByt fakeBytes := marshalHeader(t, fakeHeader) fakeHash := fakeHeader.BlockHash() err = common.ValidateBitcoinHeader(fakeBytes, fakeHash[:], 18332) - require.Error(t, err) + assert.Error(t, err) // Incorrect timestamp should fail validation // Case1: timestamp is before genesis block @@ -205,23 +205,23 @@ func validateFakeBitcoinHeader(t *testing.T, header *wire.BlockHeader, headerByt fakeBytes = marshalHeader(t, fakeHeader) fakeHash = fakeHeader.BlockHash() err = common.ValidateBitcoinHeader(fakeBytes, fakeHash[:], 18332) - require.Error(t, err) + assert.Error(t, err) // Case2: timestamp is after 2 hours in the future fakeHeader = copyHeader(header) fakeHeader.Timestamp = header.Timestamp.Add(time.Second * (blockchain.MaxTimeOffsetSeconds + 1)) fakeBytes = marshalHeader(t, fakeHeader) err = common.NewBitcoinHeader(fakeBytes).ValidateTimestamp(header.Timestamp) - require.Error(t, err) + assert.Error(t, err) // Incorrect block hash should fail validation fakeHeader = copyHeader(header) header.Nonce = 0 fakeBytes = marshalHeader(t, header) err = common.ValidateBitcoinHeader(fakeBytes, blockHash[:], 18332) - require.Error(t, err) + assert.Error(t, err) // PoW not satisfied should fail validation fakeHash = fakeHeader.BlockHash() err = common.ValidateBitcoinHeader(fakeBytes, fakeHash[:], 18332) - require.Error(t, err) + assert.Error(t, err) } diff --git a/common/proof_test.go b/common/proof_test.go index 0bf1244e80..d76dadbab0 100644 --- a/common/proof_test.go +++ b/common/proof_test.go @@ -10,7 +10,7 @@ import ( "encoding/json" "fmt" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/common" "github.com/zeta-chain/zetacore/common/bitcoin" "github.com/zeta-chain/zetacore/x/crosschain/keeper" @@ -39,21 +39,21 @@ type Blocks struct { func LoadTestBlocks(t *testing.T) Blocks { file, err := os.Open("./test_data/test_blocks.json") - require.NoError(t, err) + assert.NoError(t, err) defer file.Close() // Decode the JSON into the data struct var blocks Blocks err = json.NewDecoder(file).Decode(&blocks) - require.NoError(t, err) + assert.NoError(t, err) return blocks } func Test_IsErrorInvalidProof(t *testing.T) { - require.False(t, common.IsErrorInvalidProof(nil)) - require.False(t, common.IsErrorInvalidProof(errors.New("foo"))) - require.True(t, common.IsErrorInvalidProof(common.NewErrInvalidProof(errors.New("foo")))) + assert.False(t, common.IsErrorInvalidProof(nil)) + assert.False(t, common.IsErrorInvalidProof(errors.New("foo"))) + assert.True(t, common.IsErrorInvalidProof(common.NewErrInvalidProof(errors.New("foo")))) } func TestBitcoinMerkleProof(t *testing.T) { @@ -62,15 +62,15 @@ func TestBitcoinMerkleProof(t *testing.T) { for _, b := range blocks.Blocks { // Deserialize the header bytes from base64 headerBytes, err := base64.StdEncoding.DecodeString(b.HeaderBase64) - require.NoError(t, err) + assert.NoError(t, err) header := unmarshalHeader(t, headerBytes) // Deserialize the block bytes from base64 blockBytes, err := base64.StdEncoding.DecodeString(b.BlockBase64) - require.NoError(t, err) + assert.NoError(t, err) blockVerbose := &btcjson.GetBlockVerboseTxResult{} err = json.Unmarshal(blockBytes, blockVerbose) - require.NoError(t, err) + assert.NoError(t, err) // Validate block validateBitcoinBlock(t, header, headerBytes, blockVerbose, b.OutTxid, b.TssAddress, b.Nonce) @@ -80,23 +80,23 @@ func TestBitcoinMerkleProof(t *testing.T) { func BitcoinMerkleProofLiveTest(t *testing.T) { client := createBTCClient(t) bn, err := client.GetBlockCount() - require.NoError(t, err) + assert.NoError(t, err) fmt.Printf("Verifying transactions in block range [%d, %d]\n", bn-numBlocksToTest+1, bn) // Verify all transactions in the past 'numBlocksToTest' blocks for height := bn - numBlocksToTest + 1; height <= bn; height++ { blockHash, err := client.GetBlockHash(height) - require.NoError(t, err) + assert.NoError(t, err) // Get the block header header, err := client.GetBlockHeader(blockHash) - require.NoError(t, err) + assert.NoError(t, err) headerBytes := marshalHeader(t, header) target := blockchain.CompactToBig(header.Bits) // Get the block with verbose transactions blockVerbose, err := client.GetBlockVerboseTx(blockHash) - require.NoError(t, err) + assert.NoError(t, err) // Validate block validateBitcoinBlock(t, header, headerBytes, blockVerbose, "", "", 0) @@ -111,9 +111,9 @@ func validateBitcoinBlock(t *testing.T, _ *wire.BlockHeader, headerBytes []byte, txBodies := [][]byte{} for _, res := range blockVerbose.Tx { txBytes, err := hex.DecodeString(res.Hex) - require.NoError(t, err) + assert.NoError(t, err) tx, err := btcutil.NewTxFromBytes(txBytes) - require.NoError(t, err) + assert.NoError(t, err) // Validate Tss SegWit transaction if it's an outTx if res.Txid == outTxid { @@ -123,7 +123,7 @@ func validateBitcoinBlock(t *testing.T, _ *wire.BlockHeader, headerBytes []byte, TxHash: outTxid, } err = keeper.VerifyBTCOutTxBody(msg, txBytes, tssAddress) - require.NoError(t, err) + assert.NoError(t, err) } txns = append(txns, tx) txBodies = append(txBodies, txBytes) @@ -133,19 +133,19 @@ func validateBitcoinBlock(t *testing.T, _ *wire.BlockHeader, headerBytes []byte, mk := bitcoin.NewMerkle(txns) for i := range txns { path, index, err := mk.BuildMerkleProof(i) - require.NoError(t, err) + assert.NoError(t, err) // True proof should verify proof := common.NewBitcoinProof(txBodies[i], path, index) txBytes, err := proof.Verify(common.NewBitcoinHeader(headerBytes), 0) - require.NoError(t, err) - require.Equal(t, txBytes, txBodies[i]) + assert.NoError(t, err) + assert.Equal(t, txBytes, txBodies[i]) // Fake proof should not verify fakeIndex := index ^ 0xffffffff // flip all bits fakeProof := common.NewBitcoinProof(txBodies[i], path, fakeIndex) txBytes, err = fakeProof.Verify(common.NewBitcoinHeader(headerBytes), 0) - require.Error(t, err) - require.Nil(t, txBytes) + assert.Error(t, err) + assert.Nil(t, txBytes) } } diff --git a/contrib/localnet/orchestrator/smoketest/contracts/testdapp/TestDApp.sol b/contrib/localnet/orchestrator/smoketest/contracts/testdapp/TestDApp.sol index 700fde9447..9cb886e8d9 100644 --- a/contrib/localnet/orchestrator/smoketest/contracts/testdapp/TestDApp.sol +++ b/contrib/localnet/orchestrator/smoketest/contracts/testdapp/TestDApp.sol @@ -85,7 +85,7 @@ contract TestDApp is ZetaReceiver { function onZetaMessage(ZetaInterfaces.ZetaMessage calldata zetaMessage) external override { (, bool doRevert) = abi.decode(zetaMessage.message, (bytes32, bool)); - require(doRevert == false, "message says revert"); + assert(doRevert == false, "message says revert"); emit HelloWorldEvent(); } @@ -109,7 +109,7 @@ contract TestDApp is ZetaReceiver { function onZetaRevert(ZetaInterfaces.ZetaRevert calldata zetaRevert) external override { (, bool doRevert) = abi.decode(zetaRevert.message, (bytes32, bool)); - require(doRevert == true, "the 1st outbound was not caused by revert flag in message"); + assert(doRevert == true, "the 1st outbound was not caused by revert flag in message"); emit RevertedHelloWorldEvent(); } } \ No newline at end of file diff --git a/contrib/localnet/orchestrator/smoketest/contracts/vault/Vault.sol b/contrib/localnet/orchestrator/smoketest/contracts/vault/Vault.sol index 394c5ecc4e..84864131c2 100644 --- a/contrib/localnet/orchestrator/smoketest/contracts/vault/Vault.sol +++ b/contrib/localnet/orchestrator/smoketest/contracts/vault/Vault.sol @@ -12,21 +12,21 @@ contract Vault { mapping(address => mapping(address => uint256)) public balances; function deposit(address tokenAddress, uint256 amount) external { - require(amount > 0, "Amount should be greater than 0"); + assert(amount > 0, "Amount should be greater than 0"); IERC20 token = IERC20(tokenAddress); - require(token.transferFrom(msg.sender, address(this), amount), "Transfer failed"); + assert(token.transferFrom(msg.sender, address(this), amount), "Transfer failed"); balances[msg.sender][tokenAddress] += amount; } function withdraw(address tokenAddress, uint256 amount) external { - require(amount > 0, "Amount should be greater than 0"); - require(balances[msg.sender][tokenAddress] >= amount, "Insufficient balance"); + assert(amount > 0, "Amount should be greater than 0"); + assert(balances[msg.sender][tokenAddress] >= amount, "Insufficient balance"); balances[msg.sender][tokenAddress] -= amount; IERC20 token = IERC20(tokenAddress); - require(token.transfer(msg.sender, amount), "Transfer failed"); + assert(token.transfer(msg.sender, amount), "Transfer failed"); } } \ No newline at end of file diff --git a/rpc/ethereum/pubsub/pubsub_test.go b/rpc/ethereum/pubsub/pubsub_test.go index 9f5fe8d2e3..6788f65259 100644 --- a/rpc/ethereum/pubsub/pubsub_test.go +++ b/rpc/ethereum/pubsub/pubsub_test.go @@ -7,24 +7,24 @@ import ( "testing" "time" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" coretypes "github.com/tendermint/tendermint/rpc/core/types" ) func TestAddTopic(t *testing.T) { q := NewEventBus() err := q.AddTopic("kek", make(<-chan coretypes.ResultEvent)) - require.NoError(t, err) + assert.NoError(t, err) err = q.AddTopic("lol", make(<-chan coretypes.ResultEvent)) - require.NoError(t, err) + assert.NoError(t, err) err = q.AddTopic("lol", make(<-chan coretypes.ResultEvent)) - require.Error(t, err) + assert.Error(t, err) topics := q.Topics() sort.Strings(topics) - require.EqualValues(t, []string{"kek", "lol"}, topics) + assert.EqualValues(t, []string{"kek", "lol"}, topics) } func TestSubscribe(t *testing.T) { @@ -38,13 +38,13 @@ func TestSubscribe(t *testing.T) { q.AddTopic("lol", lolSrc) kekSubC, _, err := q.Subscribe("kek") - require.NoError(t, err) + assert.NoError(t, err) lolSubC, _, err := q.Subscribe("lol") - require.NoError(t, err) + assert.NoError(t, err) lol2SubC, _, err := q.Subscribe("lol") - require.NoError(t, err) + assert.NoError(t, err) wg := new(sync.WaitGroup) wg.Add(4) @@ -54,21 +54,21 @@ func TestSubscribe(t *testing.T) { defer wg.Done() msg := <-kekSubC log.Println("kek:", msg) - require.EqualValues(t, emptyMsg, msg) + assert.EqualValues(t, emptyMsg, msg) }() go func() { defer wg.Done() msg := <-lolSubC log.Println("lol:", msg) - require.EqualValues(t, emptyMsg, msg) + assert.EqualValues(t, emptyMsg, msg) }() go func() { defer wg.Done() msg := <-lol2SubC log.Println("lol2:", msg) - require.EqualValues(t, emptyMsg, msg) + assert.EqualValues(t, emptyMsg, msg) }() go func() { diff --git a/rpc/types/block_test.go b/rpc/types/block_test.go index 1cbb11f61e..6fd0c9ecd8 100644 --- a/rpc/types/block_test.go +++ b/rpc/types/block_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/ethereum/go-ethereum/common" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" ) func TestUnmarshalBlockNumberOrHash(t *testing.T) { @@ -21,8 +21,8 @@ func TestUnmarshalBlockNumberOrHash(t *testing.T) { "JSON input with block hash", []byte("{\"blockHash\": \"0x579917054e325746fda5c3ee431d73d26255bc4e10b51163862368629ae19739\"}"), func() { - require.Equal(t, *bnh.BlockHash, common.HexToHash("0x579917054e325746fda5c3ee431d73d26255bc4e10b51163862368629ae19739")) - require.Nil(t, bnh.BlockNumber) + assert.Equal(t, *bnh.BlockHash, common.HexToHash("0x579917054e325746fda5c3ee431d73d26255bc4e10b51163862368629ae19739")) + assert.Nil(t, bnh.BlockNumber) }, true, }, @@ -30,8 +30,8 @@ func TestUnmarshalBlockNumberOrHash(t *testing.T) { "JSON input with block number", []byte("{\"blockNumber\": \"0x35\"}"), func() { - require.Equal(t, *bnh.BlockNumber, BlockNumber(0x35)) - require.Nil(t, bnh.BlockHash) + assert.Equal(t, *bnh.BlockNumber, BlockNumber(0x35)) + assert.Nil(t, bnh.BlockHash) }, true, }, @@ -39,8 +39,8 @@ func TestUnmarshalBlockNumberOrHash(t *testing.T) { "JSON input with block number latest", []byte("{\"blockNumber\": \"latest\"}"), func() { - require.Equal(t, *bnh.BlockNumber, EthLatestBlockNumber) - require.Nil(t, bnh.BlockHash) + assert.Equal(t, *bnh.BlockNumber, EthLatestBlockNumber) + assert.Nil(t, bnh.BlockHash) }, true, }, @@ -55,8 +55,8 @@ func TestUnmarshalBlockNumberOrHash(t *testing.T) { "String input with block hash", []byte("\"0x579917054e325746fda5c3ee431d73d26255bc4e10b51163862368629ae19739\""), func() { - require.Equal(t, *bnh.BlockHash, common.HexToHash("0x579917054e325746fda5c3ee431d73d26255bc4e10b51163862368629ae19739")) - require.Nil(t, bnh.BlockNumber) + assert.Equal(t, *bnh.BlockHash, common.HexToHash("0x579917054e325746fda5c3ee431d73d26255bc4e10b51163862368629ae19739")) + assert.Nil(t, bnh.BlockNumber) }, true, }, @@ -64,8 +64,8 @@ func TestUnmarshalBlockNumberOrHash(t *testing.T) { "String input with block number", []byte("\"0x35\""), func() { - require.Equal(t, *bnh.BlockNumber, BlockNumber(0x35)) - require.Nil(t, bnh.BlockHash) + assert.Equal(t, *bnh.BlockNumber, BlockNumber(0x35)) + assert.Nil(t, bnh.BlockHash) }, true, }, @@ -73,8 +73,8 @@ func TestUnmarshalBlockNumberOrHash(t *testing.T) { "String input with block number latest", []byte("\"latest\""), func() { - require.Equal(t, *bnh.BlockNumber, EthLatestBlockNumber) - require.Nil(t, bnh.BlockHash) + assert.Equal(t, *bnh.BlockNumber, EthLatestBlockNumber) + assert.Nil(t, bnh.BlockHash) }, true, }, @@ -94,9 +94,9 @@ func TestUnmarshalBlockNumberOrHash(t *testing.T) { err := bnh.UnmarshalJSON(tc.input) tc.malleate() if tc.expPass { - require.NoError(t, err) + assert.NoError(t, err) } else { - require.Error(t, err) + assert.Error(t, err) } } } diff --git a/rpc/types/events_test.go b/rpc/types/events_test.go index f25f4489ae..e76a611b96 100644 --- a/rpc/types/events_test.go +++ b/rpc/types/events_test.go @@ -6,7 +6,7 @@ import ( "github.com/ethereum/go-ethereum/common" evmtypes "github.com/evmos/ethermint/x/evm/types" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" abci "github.com/tendermint/tendermint/abci/types" ) @@ -232,19 +232,19 @@ func TestParseTxResult(t *testing.T) { t.Run(tc.name, func(t *testing.T) { parsed, err := ParseTxResult(&tc.response, nil) if tc.expTxs == nil { - require.Error(t, err) + assert.Error(t, err) } else { - require.NoError(t, err) + assert.NoError(t, err) for msgIndex, expTx := range tc.expTxs { - require.Equal(t, expTx, parsed.GetTxByMsgIndex(msgIndex)) - require.Equal(t, expTx, parsed.GetTxByHash(expTx.Hash)) - require.Equal(t, expTx, parsed.GetTxByTxIndex(int(expTx.EthTxIndex))) + assert.Equal(t, expTx, parsed.GetTxByMsgIndex(msgIndex)) + assert.Equal(t, expTx, parsed.GetTxByHash(expTx.Hash)) + assert.Equal(t, expTx, parsed.GetTxByTxIndex(int(expTx.EthTxIndex))) } // non-exists tx hash - require.Nil(t, parsed.GetTxByHash(common.Hash{})) + assert.Nil(t, parsed.GetTxByHash(common.Hash{})) // out of range - require.Nil(t, parsed.GetTxByMsgIndex(len(tc.expTxs))) - require.Nil(t, parsed.GetTxByTxIndex(99999999)) + assert.Nil(t, parsed.GetTxByMsgIndex(len(tc.expTxs))) + assert.Nil(t, parsed.GetTxByTxIndex(99999999)) } }) } diff --git a/server/config/config_test.go b/server/config/config_test.go index 9a19e3e997..3241594e48 100644 --- a/server/config/config_test.go +++ b/server/config/config_test.go @@ -3,12 +3,12 @@ package config import ( "testing" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" ) func TestDefaultConfig(t *testing.T) { cfg := DefaultConfig() - require.True(t, cfg.JSONRPC.Enable) - require.Equal(t, cfg.JSONRPC.Address, DefaultJSONRPCAddress) - require.Equal(t, cfg.JSONRPC.WsAddress, DefaultJSONRPCWsAddress) + assert.True(t, cfg.JSONRPC.Enable) + assert.Equal(t, cfg.JSONRPC.Address, DefaultJSONRPCAddress) + assert.Equal(t, cfg.JSONRPC.WsAddress, DefaultJSONRPCWsAddress) } diff --git a/zetaclient/btc_signer_test.go b/zetaclient/btc_signer_test.go index 5c12e67876..3f40ad9de0 100644 --- a/zetaclient/btc_signer_test.go +++ b/zetaclient/btc_signer_test.go @@ -19,7 +19,6 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/rs/zerolog" "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" "github.com/zeta-chain/zetacore/zetaclient/config" . "gopkg.in/check.v1" @@ -207,26 +206,26 @@ func (s *BTCSignerSuite) TestP2WPH(c *C) { func generateKeyPair(t *testing.T, net *chaincfg.Params) (*btcec.PrivateKey, []byte) { privateKey, err := btcec.NewPrivateKey(btcec.S256()) - require.Nil(t, err) + assert.Nil(t, err) pubKeyHash := btcutil.Hash160(privateKey.PubKey().SerializeCompressed()) addr, err := btcutil.NewAddressWitnessPubKeyHash(pubKeyHash, net) - require.Nil(t, err) + assert.Nil(t, err) //fmt.Printf("New address: %s\n", addr.EncodeAddress()) pkScript, err := payToWitnessPubKeyHashScript(addr.WitnessProgram()) - require.Nil(t, err) + assert.Nil(t, err) return privateKey, pkScript } func addTxInputs(t *testing.T, tx *wire.MsgTx, txids []string) { preTxSize := tx.SerializeSize() - require.Equal(t, bytesEmptyTx, preTxSize) + assert.Equal(t, bytesEmptyTx, preTxSize) for i, txid := range txids { hash, err := chainhash.NewHashFromStr(txid) - require.Nil(t, err) + assert.Nil(t, err) outpoint := wire.NewOutPoint(hash, uint32(i%3)) txIn := wire.NewTxIn(outpoint, nil, nil) tx.AddTxIn(txIn) - require.Equal(t, bytesPerInput, tx.SerializeSize()-preTxSize) + assert.Equal(t, bytesPerInput, tx.SerializeSize()-preTxSize) //fmt.Printf("tx size: %d, input %d size: %d\n", tx.SerializeSize(), i, tx.SerializeSize()-preTxSize) preTxSize = tx.SerializeSize() } @@ -239,7 +238,7 @@ func addTxOutputs(t *testing.T, tx *wire.MsgTx, payerScript, payeeScript []byte) value1 := int64(1 + rand.Intn(100000000)) txOut1 := wire.NewTxOut(value1, payerScript) tx.AddTxOut(txOut1) - require.Equal(t, bytesPerOutput, tx.SerializeSize()-preTxSize) + assert.Equal(t, bytesPerOutput, tx.SerializeSize()-preTxSize) //fmt.Printf("tx size: %d, output 1: %d\n", tx.SerializeSize(), tx.SerializeSize()-preTxSize) preTxSize = tx.SerializeSize() @@ -247,7 +246,7 @@ func addTxOutputs(t *testing.T, tx *wire.MsgTx, payerScript, payeeScript []byte) value2 := int64(1 + rand.Intn(100000000)) txOut2 := wire.NewTxOut(value2, payeeScript) tx.AddTxOut(txOut2) - require.Equal(t, bytesPerOutput, tx.SerializeSize()-preTxSize) + assert.Equal(t, bytesPerOutput, tx.SerializeSize()-preTxSize) //fmt.Printf("tx size: %d, output 2: %d\n", tx.SerializeSize(), tx.SerializeSize()-preTxSize) preTxSize = tx.SerializeSize() @@ -255,7 +254,7 @@ func addTxOutputs(t *testing.T, tx *wire.MsgTx, payerScript, payeeScript []byte) value3 := int64(1 + rand.Intn(100000000)) txOut3 := wire.NewTxOut(value3, payeeScript) tx.AddTxOut(txOut3) - require.Equal(t, bytesPerOutput, tx.SerializeSize()-preTxSize) + assert.Equal(t, bytesPerOutput, tx.SerializeSize()-preTxSize) //fmt.Printf("tx size: %d, output 3: %d\n", tx.SerializeSize(), tx.SerializeSize()-preTxSize) } @@ -265,9 +264,9 @@ func signTx(t *testing.T, tx *wire.MsgTx, payerScript []byte, privateKey *btcec. for ix := range tx.TxIn { amount := int64(1 + rand.Intn(100000000)) witnessHash, err := txscript.CalcWitnessSigHash(payerScript, sigHashes, txscript.SigHashAll, tx, ix, amount) - require.Nil(t, err) + assert.Nil(t, err) sig, err := privateKey.Sign(witnessHash) - require.Nil(t, err) + assert.Nil(t, err) pkCompressed := privateKey.PubKey().SerializeCompressed() txWitness := wire.TxWitness{append(sig.Serialize(), byte(txscript.SigHashAll)), pkCompressed} @@ -276,11 +275,11 @@ func signTx(t *testing.T, tx *wire.MsgTx, payerScript []byte, privateKey *btcec. //fmt.Printf("tx size: %d, witness %d: %d\n", tx.SerializeSize(), ix+1, tx.SerializeSize()-preTxSize) if ix == 0 { bytesIncur := bytes1stWitness + len(tx.TxIn) - 1 // e.g., 130 bytes for a 21-input tx - require.True(t, tx.SerializeSize()-preTxSize >= bytesIncur-5) - require.True(t, tx.SerializeSize()-preTxSize <= bytesIncur+5) + assert.True(t, tx.SerializeSize()-preTxSize >= bytesIncur-5) + assert.True(t, tx.SerializeSize()-preTxSize <= bytesIncur+5) } else { - require.True(t, tx.SerializeSize()-preTxSize >= bytesPerWitness-5) - require.True(t, tx.SerializeSize()-preTxSize <= bytesPerWitness+5) + assert.True(t, tx.SerializeSize()-preTxSize >= bytesPerWitness-5) + assert.True(t, tx.SerializeSize()-preTxSize <= bytesPerWitness+5) } preTxSize = tx.SerializeSize() } @@ -311,9 +310,9 @@ func TestP2WPHSize2In3Out(t *testing.T) { // #nosec G701 always positive txSize := uint64(tx.SerializeSize()) sizeEstimated := EstimateSegWitTxSize(uint64(len(utxosTxids)), 3) - require.Equal(t, outTxBytesMin, sizeEstimated) - require.True(t, outTxBytesMin >= txSize) - require.True(t, outTxBytesMin-txSize <= 2) // 2 witness may vary + assert.Equal(t, outTxBytesMin, sizeEstimated) + assert.True(t, outTxBytesMin >= txSize) + assert.True(t, outTxBytesMin-txSize <= 2) // 2 witness may vary } func TestP2WPHSize21In3Out(t *testing.T) { @@ -348,7 +347,7 @@ func TestP2WPHSize21In3Out(t *testing.T) { // Create a new transaction and add inputs tx := wire.NewMsgTx(wire.TxVersion) - require.Equal(t, bytesEmptyTx, tx.SerializeSize()) + assert.Equal(t, bytesEmptyTx, tx.SerializeSize()) addTxInputs(t, tx, utxosTxids) // Add P2WPKH outputs @@ -361,34 +360,34 @@ func TestP2WPHSize21In3Out(t *testing.T) { // #nosec G701 always positive txSize := uint64(tx.SerializeSize()) sizeEstimated := EstimateSegWitTxSize(uint64(len(utxosTxids)), 3) - require.Equal(t, outTxBytesMax, sizeEstimated) - require.True(t, outTxBytesMax >= txSize) - require.True(t, outTxBytesMax-txSize <= 21) // 21 witness may vary + assert.Equal(t, outTxBytesMax, sizeEstimated) + assert.True(t, outTxBytesMax >= txSize) + assert.True(t, outTxBytesMax-txSize <= 21) // 21 witness may vary } func TestP2WPHSizeBreakdown(t *testing.T) { txSize2In3Out := EstimateSegWitTxSize(2, 3) - require.Equal(t, outTxBytesMin, txSize2In3Out) + assert.Equal(t, outTxBytesMin, txSize2In3Out) sz := EstimateSegWitTxSize(1, 1) fmt.Printf("1 input, 1 output: %d\n", sz) txSizeDepositor := SegWitTxSizeDepositor() - require.Equal(t, uint64(149), txSizeDepositor) + assert.Equal(t, uint64(149), txSizeDepositor) txSizeWithdrawer := SegWitTxSizeWithdrawer() - require.Equal(t, uint64(254), txSizeWithdrawer) - require.Equal(t, txSize2In3Out, txSizeDepositor+txSizeWithdrawer) // 403 = 149 + 254 + assert.Equal(t, uint64(254), txSizeWithdrawer) + assert.Equal(t, txSize2In3Out, txSizeDepositor+txSizeWithdrawer) // 403 = 149 + 254 depositFee := DepositorFee(5) - require.Equal(t, depositFee, 0.00000745) + assert.Equal(t, depositFee, 0.00000745) } // helper function to create a new BitcoinChainClient func createTestClient(t *testing.T) *BitcoinChainClient { skHex := "7b8507ba117e069f4a3f456f505276084f8c92aee86ac78ae37b4d1801d35fa8" privateKey, err := crypto.HexToECDSA(skHex) - require.Nil(t, err) + assert.Nil(t, err) tss := TestSigner{ PrivKey: privateKey, } @@ -437,85 +436,85 @@ func TestSelectUTXOs(t *testing.T) { // input: utxoCap = 5, amount = 0.01, nonce = 0 // output: [0.01], 0.01 result, amount, _, _, err := ob.SelectUTXOs(0.01, 5, 0, math.MaxUint16, true) - require.Nil(t, err) - require.Equal(t, 0.01, amount) - require.Equal(t, ob.utxos[0:1], result) + assert.Nil(t, err) + assert.Equal(t, 0.01, amount) + assert.Equal(t, ob.utxos[0:1], result) // Case2: nonce = 1, must FAIL and wait for previous transaction to be mined // input: utxoCap = 5, amount = 0.5, nonce = 1 // output: error result, amount, _, _, err = ob.SelectUTXOs(0.5, 5, 1, math.MaxUint16, true) - require.NotNil(t, err) - require.Nil(t, result) - require.Zero(t, amount) - require.Equal(t, "getOutTxidByNonce: cannot find outTx txid for nonce 0", err.Error()) + assert.NotNil(t, err) + assert.Nil(t, result) + assert.Zero(t, amount) + assert.Equal(t, "getOutTxidByNonce: cannot find outTx txid for nonce 0", err.Error()) mineTxNSetNonceMark(ob, 0, dummyTxID, -1) // mine a transaction and set nonce-mark utxo for nonce 0 // Case3: nonce = 1, should pass now // input: utxoCap = 5, amount = 0.5, nonce = 1 // output: [0.00002, 0.01, 0.12, 0.18, 0.24], 0.55002 result, amount, _, _, err = ob.SelectUTXOs(0.5, 5, 1, math.MaxUint16, true) - require.Nil(t, err) - require.Equal(t, 0.55002, amount) - require.Equal(t, ob.utxos[0:5], result) + assert.Nil(t, err) + assert.Equal(t, 0.55002, amount) + assert.Equal(t, ob.utxos[0:5], result) mineTxNSetNonceMark(ob, 1, dummyTxID, 0) // mine a transaction and set nonce-mark utxo for nonce 1 // Case4: // input: utxoCap = 5, amount = 1.0, nonce = 2 // output: [0.00002001, 0.01, 0.12, 0.18, 0.24, 0.5], 1.05002001 result, amount, _, _, err = ob.SelectUTXOs(1.0, 5, 2, math.MaxUint16, true) - require.Nil(t, err) + assert.Nil(t, err) assert.InEpsilon(t, 1.05002001, amount, 1e-8) - require.Equal(t, ob.utxos[0:6], result) + assert.Equal(t, ob.utxos[0:6], result) mineTxNSetNonceMark(ob, 2, dummyTxID, 0) // mine a transaction and set nonce-mark utxo for nonce 2 // Case5: should include nonce-mark utxo on the LEFT // input: utxoCap = 5, amount = 8.05, nonce = 3 // output: [0.00002002, 0.24, 0.5, 1.26, 2.97, 3.28], 8.25002002 result, amount, _, _, err = ob.SelectUTXOs(8.05, 5, 3, math.MaxUint16, true) - require.Nil(t, err) + assert.Nil(t, err) assert.InEpsilon(t, 8.25002002, amount, 1e-8) expected := append([]btcjson.ListUnspentResult{ob.utxos[0]}, ob.utxos[4:9]...) - require.Equal(t, expected, result) + assert.Equal(t, expected, result) mineTxNSetNonceMark(ob, 24105431, dummyTxID, 0) // mine a transaction and set nonce-mark utxo for nonce 24105431 // Case6: should include nonce-mark utxo on the RIGHT // input: utxoCap = 5, amount = 0.503, nonce = 24105432 // output: [0.24107432, 0.01, 0.12, 0.18, 0.24], 0.55002002 result, amount, _, _, err = ob.SelectUTXOs(0.503, 5, 24105432, math.MaxUint16, true) - require.Nil(t, err) + assert.Nil(t, err) assert.InEpsilon(t, 0.79107431, amount, 1e-8) expected = append([]btcjson.ListUnspentResult{ob.utxos[4]}, ob.utxos[0:4]...) - require.Equal(t, expected, result) + assert.Equal(t, expected, result) mineTxNSetNonceMark(ob, 24105432, dummyTxID, 4) // mine a transaction and set nonce-mark utxo for nonce 24105432 // Case7: should include nonce-mark utxo in the MIDDLE // input: utxoCap = 5, amount = 1.0, nonce = 24105433 // output: [0.24107432, 0.12, 0.18, 0.24, 0.5], 1.28107432 result, amount, _, _, err = ob.SelectUTXOs(1.0, 5, 24105433, math.MaxUint16, true) - require.Nil(t, err) + assert.Nil(t, err) assert.InEpsilon(t, 1.28107432, amount, 1e-8) expected = append([]btcjson.ListUnspentResult{ob.utxos[4]}, ob.utxos[1:4]...) expected = append(expected, ob.utxos[5]) - require.Equal(t, expected, result) + assert.Equal(t, expected, result) // Case8: should work with maximum amount // input: utxoCap = 5, amount = 16.03 // output: [0.24107432, 1.26, 2.97, 3.28, 5.16, 8.72], 21.63107432 result, amount, _, _, err = ob.SelectUTXOs(16.03, 5, 24105433, math.MaxUint16, true) - require.Nil(t, err) + assert.Nil(t, err) assert.InEpsilon(t, 21.63107432, amount, 1e-8) expected = append([]btcjson.ListUnspentResult{ob.utxos[4]}, ob.utxos[6:11]...) - require.Equal(t, expected, result) + assert.Equal(t, expected, result) // Case9: must FAIL due to insufficient funds // input: utxoCap = 5, amount = 21.64 // output: error result, amount, _, _, err = ob.SelectUTXOs(21.64, 5, 24105433, math.MaxUint16, true) - require.NotNil(t, err) - require.Nil(t, result) - require.Zero(t, amount) - require.Equal(t, "SelectUTXOs: not enough btc in reserve - available : 21.63107432 , tx amount : 21.64", err.Error()) + assert.NotNil(t, err) + assert.Nil(t, result) + assert.Zero(t, amount) + assert.Equal(t, "SelectUTXOs: not enough btc in reserve - available : 21.63107432 , tx amount : 21.64", err.Error()) } func TestUTXOConsolidation(t *testing.T) { @@ -528,11 +527,11 @@ func TestUTXOConsolidation(t *testing.T) { // input: utxoCap = 10, amount = 0.01, nonce = 1, rank = 10 // output: [0.00002, 0.01], 0.01002 result, amount, clsdtUtxo, clsdtValue, err := ob.SelectUTXOs(0.01, 10, 1, 10, true) - require.Nil(t, err) - require.Equal(t, 0.01002, amount) - require.Equal(t, ob.utxos[0:2], result) - require.Equal(t, uint16(0), clsdtUtxo) - require.Equal(t, 0.0, clsdtValue) + assert.Nil(t, err) + assert.Equal(t, 0.01002, amount) + assert.Equal(t, ob.utxos[0:2], result) + assert.Equal(t, uint16(0), clsdtUtxo) + assert.Equal(t, 0.0, clsdtValue) }) t.Run("should consolidate 1 utxo", func(t *testing.T) { @@ -542,11 +541,11 @@ func TestUTXOConsolidation(t *testing.T) { // input: utxoCap = 9, amount = 0.01, nonce = 1, rank = 9 // output: [0.00002, 0.01, 0.12], 0.13002 result, amount, clsdtUtxo, clsdtValue, err := ob.SelectUTXOs(0.01, 9, 1, 9, true) - require.Nil(t, err) - require.Equal(t, 0.13002, amount) - require.Equal(t, ob.utxos[0:3], result) - require.Equal(t, uint16(1), clsdtUtxo) - require.Equal(t, 0.12, clsdtValue) + assert.Nil(t, err) + assert.Equal(t, 0.13002, amount) + assert.Equal(t, ob.utxos[0:3], result) + assert.Equal(t, uint16(1), clsdtUtxo) + assert.Equal(t, 0.12, clsdtValue) }) t.Run("should consolidate 3 utxos", func(t *testing.T) { @@ -556,16 +555,16 @@ func TestUTXOConsolidation(t *testing.T) { // input: utxoCap = 5, amount = 0.01, nonce = 0, rank = 5 // output: [0.00002, 0.014, 1.26, 0.5, 0.2], 2.01002 result, amount, clsdtUtxo, clsdtValue, err := ob.SelectUTXOs(0.01, 5, 1, 5, true) - require.Nil(t, err) - require.Equal(t, 2.01002, amount) + assert.Nil(t, err) + assert.Equal(t, 2.01002, amount) expected := make([]btcjson.ListUnspentResult, 2) copy(expected, ob.utxos[0:2]) for i := 6; i >= 4; i-- { // append consolidated utxos in descending order expected = append(expected, ob.utxos[i]) } - require.Equal(t, expected, result) - require.Equal(t, uint16(3), clsdtUtxo) - require.Equal(t, 2.0, clsdtValue) + assert.Equal(t, expected, result) + assert.Equal(t, uint16(3), clsdtUtxo) + assert.Equal(t, 2.0, clsdtValue) }) t.Run("should consolidate all utxos using rank 1", func(t *testing.T) { @@ -575,16 +574,16 @@ func TestUTXOConsolidation(t *testing.T) { // input: utxoCap = 12, amount = 0.01, nonce = 0, rank = 1 // output: [0.00002, 0.01, 8.72, 5.16, 3.28, 2.97, 1.26, 0.5, 0.24, 0.18, 0.12], 22.44002 result, amount, clsdtUtxo, clsdtValue, err := ob.SelectUTXOs(0.01, 12, 1, 1, true) - require.Nil(t, err) - require.Equal(t, 22.44002, amount) + assert.Nil(t, err) + assert.Equal(t, 22.44002, amount) expected := make([]btcjson.ListUnspentResult, 2) copy(expected, ob.utxos[0:2]) for i := 10; i >= 2; i-- { // append consolidated utxos in descending order expected = append(expected, ob.utxos[i]) } - require.Equal(t, expected, result) - require.Equal(t, uint16(9), clsdtUtxo) - require.Equal(t, 22.43, clsdtValue) + assert.Equal(t, expected, result) + assert.Equal(t, uint16(9), clsdtUtxo) + assert.Equal(t, 22.43, clsdtValue) }) t.Run("should consolidate 3 utxos sparse", func(t *testing.T) { @@ -594,15 +593,15 @@ func TestUTXOConsolidation(t *testing.T) { // input: utxoCap = 5, amount = 0.13, nonce = 24105432, rank = 5 // output: [0.24107431, 0.01, 0.12, 1.26, 0.5, 0.24], 2.37107431 result, amount, clsdtUtxo, clsdtValue, err := ob.SelectUTXOs(0.13, 5, 24105432, 5, true) - require.Nil(t, err) + assert.Nil(t, err) assert.InEpsilon(t, 2.37107431, amount, 1e-8) expected := append([]btcjson.ListUnspentResult{ob.utxos[4]}, ob.utxos[0:2]...) expected = append(expected, ob.utxos[6]) expected = append(expected, ob.utxos[5]) expected = append(expected, ob.utxos[3]) - require.Equal(t, expected, result) - require.Equal(t, uint16(3), clsdtUtxo) - require.Equal(t, 2.0, clsdtValue) + assert.Equal(t, expected, result) + assert.Equal(t, uint16(3), clsdtUtxo) + assert.Equal(t, 2.0, clsdtValue) }) t.Run("should consolidate all utxos sparse", func(t *testing.T) { @@ -612,7 +611,7 @@ func TestUTXOConsolidation(t *testing.T) { // input: utxoCap = 12, amount = 0.13, nonce = 24105432, rank = 1 // output: [0.24107431, 0.01, 0.12, 8.72, 5.16, 3.28, 2.97, 1.26, 0.5, 0.24, 0.18], 22.68107431 result, amount, clsdtUtxo, clsdtValue, err := ob.SelectUTXOs(0.13, 12, 24105432, 1, true) - require.Nil(t, err) + assert.Nil(t, err) assert.InEpsilon(t, 22.68107431, amount, 1e-8) expected := append([]btcjson.ListUnspentResult{ob.utxos[4]}, ob.utxos[0:2]...) for i := 10; i >= 5; i-- { // append consolidated utxos in descending order @@ -620,8 +619,8 @@ func TestUTXOConsolidation(t *testing.T) { } expected = append(expected, ob.utxos[3]) expected = append(expected, ob.utxos[2]) - require.Equal(t, expected, result) - require.Equal(t, uint16(8), clsdtUtxo) - require.Equal(t, 22.31, clsdtValue) + assert.Equal(t, expected, result) + assert.Equal(t, uint16(8), clsdtUtxo) + assert.Equal(t, 22.31, clsdtValue) }) } diff --git a/zetaclient/hsm/hsm_signer_test.go b/zetaclient/hsm/hsm_signer_test.go index 5c7ba38099..2c35f8b625 100644 --- a/zetaclient/hsm/hsm_signer_test.go +++ b/zetaclient/hsm/hsm_signer_test.go @@ -12,7 +12,7 @@ import ( btcsecp256k1 "github.com/btcsuite/btcd/btcec" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" keystone "github.com/zeta-chain/keystone/keys" ) @@ -26,20 +26,20 @@ func TestSignSecp256k1(t *testing.T) { //Generate random label for key label, err := randomBytes(16) - require.NoError(t, err) + assert.NoError(t, err) //Generate key key, err := GenerateKey(string(label), keystone.KEYGEN_SECP256K1, config) - require.NoError(t, err) - require.NotNil(t, key) + assert.NoError(t, err) + assert.NotNil(t, key) //Create sample message msg := []byte("Signing this plaintext tells me what exactly?") signature, err := Sign(config, msg, string(label)) - require.NoError(t, err) - require.NotNil(t, signature) - require.Equal(t, key.KeyType(), keystone.KEYGEN_SECP256K1) + assert.NoError(t, err) + assert.NotNil(t, signature) + assert.Equal(t, key.KeyType(), keystone.KEYGEN_SECP256K1) pubkey := key.PubKey() secp256k1key := pubkey.(*secp256k1.PubKey) @@ -57,7 +57,7 @@ func TestSignSecp256k1(t *testing.T) { log.Printf("Address from HSM: %v, PubKey from HSM: %v", address, pubKey) err = key.Delete() - require.NoError(t, err) + assert.NoError(t, err) } func randomBytes(n int) ([]byte, error) { diff --git a/zetaclient/utils_test.go b/zetaclient/utils_test.go index 98355e82ac..994c562bf1 100644 --- a/zetaclient/utils_test.go +++ b/zetaclient/utils_test.go @@ -6,7 +6,7 @@ import ( ethcommon "github.com/ethereum/go-ethereum/common" ethtypes "github.com/ethereum/go-ethereum/core/types" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" ) func TestCheckEvmTxLog(t *testing.T) { @@ -92,10 +92,10 @@ func TestCheckEvmTxLog(t *testing.T) { TopicsZetaSent, ) if tt.fail { - require.Error(t, err) + assert.Error(t, err) return } else { - require.NoError(t, err) + assert.NoError(t, err) } }) } From 787a686d928ba93e6e986fe69d05a0026a958e37 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Fri, 2 Feb 2024 14:29:36 -0500 Subject: [PATCH 08/13] use assert in zetaclient directory --- changelog.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 19c19d24d4..4fb28e0d31 100644 --- a/changelog.md +++ b/changelog.md @@ -5,6 +5,9 @@ ### Fixes * [1610](https://github.com/zeta-chain/node/issues/1610) - add pending outtx hash to tracker after monitoring for 10 minutes +## Chores +* [1694](https://github.com/zeta-chain/node/pull/1694) - remove standalone network, use assert testing package for the entire node folder + ## Version: v12.1.0 ### Tests @@ -28,7 +31,7 @@ * [1585](https://github.com/zeta-chain/node/pull/1585) - Updated release instructions * [1615](https://github.com/zeta-chain/node/pull/1615) - Add upgrade handler for version v12.1.0 -* [1694](https://github.com/zeta-chain/node/pull/1694) - remove standalone network + ### Features From f9c620423a8c5afffccc7fba04d4d74c29306997 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Tue, 6 Feb 2024 00:48:27 -0500 Subject: [PATCH 09/13] remove required from testutil folder --- testutil/contracts/Example.sol | 2 +- testutil/keeper/crosschain.go | 14 +++++++------- testutil/keeper/observer.go | 4 ++-- testutil/sample/sample.go | 6 +++--- testutil/sample/sample_test.go | 6 +++--- testutil/simapp/simapp.go | 8 ++++---- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/testutil/contracts/Example.sol b/testutil/contracts/Example.sol index 1b36e7a15d..f406d86023 100644 --- a/testutil/contracts/Example.sol +++ b/testutil/contracts/Example.sol @@ -26,7 +26,7 @@ contract Example { } function doRevertWithRequire() external { - require(false, "foo"); + assert(false, "foo"); } function doSucceed() external { diff --git a/testutil/keeper/crosschain.go b/testutil/keeper/crosschain.go index 69f2ae68f4..b6a5aa428a 100644 --- a/testutil/keeper/crosschain.go +++ b/testutil/keeper/crosschain.go @@ -6,7 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/store" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" tmdb "github.com/tendermint/tm-db" crosschainmocks "github.com/zeta-chain/zetacore/testutil/keeper/mocks/crosschain" "github.com/zeta-chain/zetacore/x/crosschain/keeper" @@ -78,7 +78,7 @@ func CrosschainKeeperWithMocks( // Create the fungible keeper stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db) stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil) - require.NoError(t, stateStore.LoadLatestVersion()) + assert.NoError(t, stateStore.LoadLatestVersion()) ctx := NewContext(stateStore) @@ -137,30 +137,30 @@ func CrosschainKeeper(t testing.TB) (*keeper.Keeper, sdk.Context, SDKKeepers, Ze func GetCrosschainAccountMock(t testing.TB, keeper *keeper.Keeper) *crosschainmocks.CrosschainAccountKeeper { cak, ok := keeper.GetAuthKeeper().(*crosschainmocks.CrosschainAccountKeeper) - require.True(t, ok) + assert.True(t, ok) return cak } func GetCrosschainBankMock(t testing.TB, keeper *keeper.Keeper) *crosschainmocks.CrosschainBankKeeper { cbk, ok := keeper.GetBankKeeper().(*crosschainmocks.CrosschainBankKeeper) - require.True(t, ok) + assert.True(t, ok) return cbk } func GetCrosschainStakingMock(t testing.TB, keeper *keeper.Keeper) *crosschainmocks.CrosschainStakingKeeper { csk, ok := keeper.GetStakingKeeper().(*crosschainmocks.CrosschainStakingKeeper) - require.True(t, ok) + assert.True(t, ok) return csk } func GetCrosschainObserverMock(t testing.TB, keeper *keeper.Keeper) *crosschainmocks.CrosschainObserverKeeper { cok, ok := keeper.GetObserverKeeper().(*crosschainmocks.CrosschainObserverKeeper) - require.True(t, ok) + assert.True(t, ok) return cok } func GetCrosschainFungibleMock(t testing.TB, keeper *keeper.Keeper) *crosschainmocks.CrosschainFungibleKeeper { cfk, ok := keeper.GetFungibleKeeper().(*crosschainmocks.CrosschainFungibleKeeper) - require.True(t, ok) + assert.True(t, ok) return cfk } diff --git a/testutil/keeper/observer.go b/testutil/keeper/observer.go index 946dac84c6..0d2395af70 100644 --- a/testutil/keeper/observer.go +++ b/testutil/keeper/observer.go @@ -11,7 +11,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" tmdb "github.com/tendermint/tm-db" "github.com/zeta-chain/zetacore/x/observer/keeper" "github.com/zeta-chain/zetacore/x/observer/types" @@ -56,7 +56,7 @@ func ObserverKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) { // Create the observer keeper stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db) stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil) - require.NoError(t, stateStore.LoadLatestVersion()) + assert.NoError(t, stateStore.LoadLatestVersion()) ctx := NewContext(stateStore) diff --git a/testutil/sample/sample.go b/testutil/sample/sample.go index 4fcc9ac9e8..a6f2a3aeac 100644 --- a/testutil/sample/sample.go +++ b/testutil/sample/sample.go @@ -15,7 +15,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ethcommon "github.com/ethereum/go-ethereum/common" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/zeta-chain/zetacore/common" "github.com/zeta-chain/zetacore/common/cosmos" ) @@ -30,7 +30,7 @@ func newRandFromSeed(s int64) *rand.Rand { func newRandFromStringSeed(t *testing.T, s string) *rand.Rand { h := fnv.New64a() _, err := h.Write([]byte(s)) - require.NoError(t, err) + assert.NoError(t, err) return newRandFromSeed(int64(h.Sum64())) } @@ -70,7 +70,7 @@ func Validator(t testing.TB, r *rand.Rand) stakingtypes.Validator { ValAddress(r), ed25519.GenPrivKeyFromSecret(seed).PubKey(), stakingtypes.Description{}) - require.NoError(t, err) + assert.NoError(t, err) return val } diff --git a/testutil/sample/sample_test.go b/testutil/sample/sample_test.go index 3cd0687c08..b940760e03 100644 --- a/testutil/sample/sample_test.go +++ b/testutil/sample/sample_test.go @@ -4,14 +4,14 @@ import ( "testing" ethcommon "github.com/ethereum/go-ethereum/common" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" ) func TestEthAddress(t *testing.T) { ethAddress := EthAddress() - require.NotEqual(t, ethcommon.Address{}, ethAddress) + assert.NotEqual(t, ethcommon.Address{}, ethAddress) // don't generate the same address ethAddress2 := EthAddress() - require.NotEqual(t, ethAddress, ethAddress2) + assert.NotEqual(t, ethAddress, ethAddress2) } diff --git a/testutil/simapp/simapp.go b/testutil/simapp/simapp.go index cde89abbab..cb3766e7e9 100644 --- a/testutil/simapp/simapp.go +++ b/testutil/simapp/simapp.go @@ -12,7 +12,7 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmtypes "github.com/tendermint/tendermint/types" "github.com/zeta-chain/zetacore/cmd/zetacored/config" @@ -70,9 +70,9 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genDelAc // Make all members of delSet as delegators to each of the validators for _, val := range valSet.Validators { pk, err := cryptocodec.FromTmPubKeyInterface(val.PubKey) - require.NoError(t, err) + assert.NoError(t, err) pkAny, err := codectypes.NewAnyWithValue(pk) - require.NoError(t, err) + assert.NoError(t, err) validator := stakingtypes.Validator{ OperatorAddress: sdk.ValAddress(val.Address).String(), ConsensusPubkey: pkAny, @@ -127,7 +127,7 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genDelAc genesisState[banktypes.ModuleName] = app.AppCodec().MustMarshalJSON(bankGenesis) stateBytes, err := json.MarshalIndent(genesisState, "", " ") - require.NoError(t, err) + assert.NoError(t, err) // init chain will set the validator set and initialize the genesis accounts app.InitChain( From 08abc49f02cd5c83b09be33363700b3eb5748435 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Tue, 6 Feb 2024 01:50:44 -0500 Subject: [PATCH 10/13] undo replace in solidity files --- .../smoketest/contracts/testdapp/TestDApp.sol | 4 ++-- .../orchestrator/smoketest/contracts/vault/Vault.sol | 10 +++++----- testutil/contracts/Example.sol | 2 +- .../keeper/msg_server_update_zrc20_paused_status.go | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/contrib/localnet/orchestrator/smoketest/contracts/testdapp/TestDApp.sol b/contrib/localnet/orchestrator/smoketest/contracts/testdapp/TestDApp.sol index 9cb886e8d9..700fde9447 100644 --- a/contrib/localnet/orchestrator/smoketest/contracts/testdapp/TestDApp.sol +++ b/contrib/localnet/orchestrator/smoketest/contracts/testdapp/TestDApp.sol @@ -85,7 +85,7 @@ contract TestDApp is ZetaReceiver { function onZetaMessage(ZetaInterfaces.ZetaMessage calldata zetaMessage) external override { (, bool doRevert) = abi.decode(zetaMessage.message, (bytes32, bool)); - assert(doRevert == false, "message says revert"); + require(doRevert == false, "message says revert"); emit HelloWorldEvent(); } @@ -109,7 +109,7 @@ contract TestDApp is ZetaReceiver { function onZetaRevert(ZetaInterfaces.ZetaRevert calldata zetaRevert) external override { (, bool doRevert) = abi.decode(zetaRevert.message, (bytes32, bool)); - assert(doRevert == true, "the 1st outbound was not caused by revert flag in message"); + require(doRevert == true, "the 1st outbound was not caused by revert flag in message"); emit RevertedHelloWorldEvent(); } } \ No newline at end of file diff --git a/contrib/localnet/orchestrator/smoketest/contracts/vault/Vault.sol b/contrib/localnet/orchestrator/smoketest/contracts/vault/Vault.sol index 84864131c2..394c5ecc4e 100644 --- a/contrib/localnet/orchestrator/smoketest/contracts/vault/Vault.sol +++ b/contrib/localnet/orchestrator/smoketest/contracts/vault/Vault.sol @@ -12,21 +12,21 @@ contract Vault { mapping(address => mapping(address => uint256)) public balances; function deposit(address tokenAddress, uint256 amount) external { - assert(amount > 0, "Amount should be greater than 0"); + require(amount > 0, "Amount should be greater than 0"); IERC20 token = IERC20(tokenAddress); - assert(token.transferFrom(msg.sender, address(this), amount), "Transfer failed"); + require(token.transferFrom(msg.sender, address(this), amount), "Transfer failed"); balances[msg.sender][tokenAddress] += amount; } function withdraw(address tokenAddress, uint256 amount) external { - assert(amount > 0, "Amount should be greater than 0"); - assert(balances[msg.sender][tokenAddress] >= amount, "Insufficient balance"); + require(amount > 0, "Amount should be greater than 0"); + require(balances[msg.sender][tokenAddress] >= amount, "Insufficient balance"); balances[msg.sender][tokenAddress] -= amount; IERC20 token = IERC20(tokenAddress); - assert(token.transfer(msg.sender, amount), "Transfer failed"); + require(token.transfer(msg.sender, amount), "Transfer failed"); } } \ No newline at end of file diff --git a/testutil/contracts/Example.sol b/testutil/contracts/Example.sol index f406d86023..1b36e7a15d 100644 --- a/testutil/contracts/Example.sol +++ b/testutil/contracts/Example.sol @@ -26,7 +26,7 @@ contract Example { } function doRevertWithRequire() external { - assert(false, "foo"); + require(false, "foo"); } function doSucceed() external { diff --git a/x/fungible/keeper/msg_server_update_zrc20_paused_status.go b/x/fungible/keeper/msg_server_update_zrc20_paused_status.go index 8605678cf9..e5527071ea 100644 --- a/x/fungible/keeper/msg_server_update_zrc20_paused_status.go +++ b/x/fungible/keeper/msg_server_update_zrc20_paused_status.go @@ -27,7 +27,7 @@ func (k msgServer) UpdateZRC20PausedStatus( } // check if the sender is the admin - // unpausing asserts group2 admin + // unpausing requires group2 admin requiredPolicyAccount := zetaObserverTypes.Policy_Type_group1 if msg.Action == types.UpdatePausedStatusAction_UNPAUSE { requiredPolicyAccount = zetaObserverTypes.Policy_Type_group2 From 58b00d406949c5bc79db9599eb36abcd4492dfc7 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Tue, 6 Feb 2024 02:09:09 -0500 Subject: [PATCH 11/13] rebase develop 1 --- testutil/keeper/emissions.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testutil/keeper/emissions.go b/testutil/keeper/emissions.go index edcde7a75e..65ca6f4e5b 100644 --- a/testutil/keeper/emissions.go +++ b/testutil/keeper/emissions.go @@ -12,7 +12,7 @@ import ( bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" typesparams "github.com/cosmos/cosmos-sdk/x/params/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - "github.com/stretchr/testify/require" + "github.com/stretchr/testify/assert" "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmdb "github.com/tendermint/tm-db" @@ -29,7 +29,7 @@ func EmissionsKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) { stateStore := store.NewCommitMultiStore(db) stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db) stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, db) - require.NoError(t, stateStore.LoadLatestVersion()) + assert.NoError(t, stateStore.LoadLatestVersion()) registry := codectypes.NewInterfaceRegistry() cdc := codec.NewProtoCodec(registry) From ac6ce000c4fe690d25c30aa1d3d78f8964f532bd Mon Sep 17 00:00:00 2001 From: Tanmay Date: Fri, 9 Feb 2024 00:36:17 -0500 Subject: [PATCH 12/13] use require --- app/ante/ante_test.go | 4 +- app/ante/vesting_test.go | 10 +- changelog.md | 2 +- cmd/zetacored/flags_test.go | 8 +- cmd/zetacored/parsers_test.go | 8 +- common/address_test.go | 16 +- common/chain_id_test.go | 8 +- common/chain_test.go | 16 +- common/coin_test.go | 18 +- common/headers_test.go | 54 ++--- common/proof_test.go | 42 ++-- testutil/keeper/crosschain.go | 14 +- testutil/keeper/emissions.go | 4 +- testutil/keeper/fungible.go | 9 +- testutil/keeper/observer.go | 4 +- testutil/network/genesis_state.go | 36 ++-- testutil/sample/sample.go | 6 +- testutil/sample/sample_test.go | 6 +- testutil/simapp/simapp.go | 8 +- .../client/cli/cli_out_tx_tracker_test.go | 44 ++-- .../client/integrationtests/cli_helpers.go | 38 ++-- x/crosschain/genesis_test.go | 6 +- x/crosschain/keeper/abci_test.go | 50 ++--- x/crosschain/keeper/cctx_test.go | 34 ++-- x/crosschain/keeper/cctx_utils_test.go | 56 +++--- x/crosschain/keeper/evm_deposit_test.go | 48 ++--- .../keeper/finalized_inbounds_test.go | 18 +- x/crosschain/keeper/gas_payment_test.go | 88 ++++---- x/crosschain/keeper/gas_price_test.go | 10 +- x/crosschain/keeper/grpc_query_cctx_test.go | 46 ++--- .../keeper/grpc_query_gas_price_test.go | 20 +- .../grpc_query_in_tx_hash_to_cctx_test.go | 38 ++-- .../grpc_query_last_block_height_test.go | 20 +- .../keeper/grpc_query_out_tx_tracker_test.go | 26 +-- .../keeper/in_tx_hash_to_cctx_test.go | 10 +- x/crosschain/keeper/in_tx_tracker_test.go | 36 ++-- x/crosschain/keeper/keeper_test.go | 4 +- x/crosschain/keeper/last_block_height_test.go | 10 +- .../msg_server_abort_stuck_cctx_test.go | 32 +-- .../msg_server_add_to_intx_tracker_test.go | 34 ++-- .../msg_server_add_to_outtx_tracker_test.go | 74 +++---- .../msg_server_migrate_tss_funds_test.go | 48 ++--- .../keeper/msg_server_update_tss_test.go | 72 +++---- .../keeper/msg_server_vote_inbound_tx_test.go | 30 +-- .../msg_server_vote_outbound_tx_test.go | 6 +- .../keeper/msg_server_whitelist_erc20_test.go | 36 ++-- x/crosschain/keeper/out_tx_tracker_test.go | 10 +- x/crosschain/keeper/utils_test.go | 46 ++--- x/crosschain/keeper/zeta_accounting_test.go | 18 +- x/crosschain/migrations/v4/migrate_test.go | 44 ++-- x/crosschain/types/cctx_utils_test.go | 26 +-- x/crosschain/types/genesis_test.go | 6 +- .../types/message_abort_stuck_cctx_test.go | 6 +- .../message_add_to_in_tx_tracker_test.go | 6 +- .../message_add_to_out_tx_tracker_test.go | 6 +- .../types/message_migrate_tss_funds_test.go | 6 +- .../types/message_update_tss_address_test.go | 6 +- ...essage_vote_on_observed_inbound_tx_test.go | 36 ++-- ...ssage_vote_on_observed_outbound_tx_test.go | 32 +-- x/emissions/abci_test.go | 14 +- x/emissions/genesis_test.go | 6 +- .../keeper/block_rewards_components_test.go | 6 +- x/emissions/keeper/params_test.go | 8 +- x/emissions/types/genesis_test.go | 6 +- .../client/cli/query_foreign_coins_test.go | 44 ++-- x/fungible/genesis_test.go | 6 +- x/fungible/keeper/deposits_test.go | 70 +++---- x/fungible/keeper/evm_hooks_test.go | 14 +- x/fungible/keeper/evm_test.go | 190 +++++++++--------- x/fungible/keeper/foreign_coins_test.go | 26 +-- x/fungible/keeper/gas_coin_and_pool_test.go | 10 +- x/fungible/keeper/gas_price_test.go | 32 +-- x/fungible/keeper/gas_stability_pool_test.go | 32 +-- .../keeper/grpc_query_code_hash_test.go | 22 +- .../keeper/grpc_query_foreign_coins_test.go | 28 +-- x/fungible/keeper/grpc_query_params_test.go | 6 +- ..._server_deploy_fungible_coin_zrc20_test.go | 60 +++--- .../msg_server_deploy_system_contract_test.go | 12 +- .../msg_server_remove_foreign_coin_test.go | 16 +- ..._server_udpate_zrc20_liquidity_cap_test.go | 34 ++-- ...sg_server_update_contract_bytecode_test.go | 86 ++++---- .../msg_server_update_system_contract_test.go | 54 ++--- ..._server_update_zrc20_paused_status_test.go | 30 +-- ...g_server_update_zrc20_withdraw_fee_test.go | 60 +++--- x/fungible/keeper/params_test.go | 4 +- x/fungible/keeper/system_contract_test.go | 60 +++--- x/fungible/keeper/zeta_test.go | 12 +- x/fungible/types/evm_test.go | 14 +- x/fungible/types/gas_stablity_pool_test.go | 6 +- x/fungible/types/genesis_test.go | 6 +- ...message_deploy_fungible_coin_zrc20_test.go | 6 +- .../message_deploy_system_contracts_test.go | 6 +- .../types/message_remove_foreign_coin_test.go | 6 +- .../message_update_contract_bytecode_test.go | 6 +- .../message_update_system_contract_test.go | 6 +- ...message_update_zrc20_liquidity_cap_test.go | 6 +- ...message_update_zrc20_paused_status_test.go | 6 +- .../message_update_zrc20_withdraw_fee_test.go | 6 +- x/observer/genesis_test.go | 6 +- x/observer/keeper/chain_nonces_test.go | 10 +- x/observer/keeper/chain_params_test.go | 26 +-- x/observer/keeper/grpc_query_blame_test.go | 30 +-- x/observer/keeper/grpc_query_keygen_test.go | 6 +- .../keeper/grpc_query_node_account_test.go | 20 +- x/observer/keeper/grpc_query_nonces_test.go | 20 +- x/observer/keeper/grpc_query_params_test.go | 6 +- x/observer/keeper/keeper_test.go | 4 +- x/observer/keeper/keygen_test.go | 8 +- .../msg_server_add_block_header_test.go | 42 ++-- .../msg_server_remove_chain_params_test.go | 36 ++-- .../msg_server_update_chain_params_test.go | 50 ++--- ...msg_server_update_crosschain_flags_test.go | 98 ++++----- .../keeper/msg_server_update_observer_test.go | 80 ++++---- x/observer/keeper/node_account_test.go | 10 +- x/observer/keeper/nonce_to_cctx_test.go | 10 +- x/observer/keeper/nonces_test.go | 10 +- x/observer/keeper/observer_set_test.go | 42 ++-- x/observer/keeper/params_test.go | 4 +- x/observer/keeper/pending_nonces_test.go | 20 +- x/observer/keeper/tss_funds_migrator_test.go | 10 +- x/observer/keeper/tss_test.go | 40 ++-- x/observer/keeper/utils_test.go | 16 +- x/observer/migrations/v3/migrate_test.go | 18 +- x/observer/migrations/v4/migrate_test.go | 10 +- x/observer/migrations/v5/migrate_test.go | 42 ++-- x/observer/migrations/v6/migrate_test.go | 22 +- x/observer/types/ballot_test.go | 14 +- x/observer/types/chain_params_test.go | 64 +++--- x/observer/types/genesis_test.go | 6 +- x/observer/types/message_add_observer_test.go | 6 +- .../types/message_crosschain_flags_test.go | 12 +- .../types/message_remove_chain_params_test.go | 6 +- .../message_set_ballot_threshold_test.go | 4 +- .../types/message_update_chain_params_test.go | 6 +- .../types/message_update_keygen_test.go | 6 +- .../types/message_update_observer_test.go | 6 +- zetaclient/btc_signer_test.go | 174 ++++++++-------- zetaclient/hsm/hsm_signer_test.go | 16 +- zetaclient/tss_signer_test.go | 10 +- zetaclient/utils_test.go | 6 +- zetaclient/zeta_supply_checker_test.go | 8 +- 141 files changed, 1758 insertions(+), 1759 deletions(-) diff --git a/app/ante/ante_test.go b/app/ante/ante_test.go index f5c8bc53f4..146e50c6ae 100644 --- a/app/ante/ante_test.go +++ b/app/ante/ante_test.go @@ -7,7 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/authz" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/app" "github.com/zeta-chain/zetacore/app/ante" "github.com/zeta-chain/zetacore/testutil/sample" @@ -226,7 +226,7 @@ func TestIsSystemTx(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { is := ante.IsSystemTx(tt.tx, tt.isAuthorized) - assert.Equal(t, tt.wantIs, is) + require.Equal(t, tt.wantIs, is) }) } } diff --git a/app/ante/vesting_test.go b/app/ante/vesting_test.go index 3310b55b3b..fac1cb16d5 100644 --- a/app/ante/vesting_test.go +++ b/app/ante/vesting_test.go @@ -9,7 +9,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" vesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/app" "github.com/zeta-chain/zetacore/app/ante" @@ -86,7 +86,7 @@ func TestVesting_AnteHandle(t *testing.T) { []uint64{0}, testPrivKey, ) - assert.NoError(t, err) + require.NoError(t, err) mmd := MockAnteHandler{} ctx := sdk.Context{}.WithIsCheckTx(true) @@ -94,10 +94,10 @@ func TestVesting_AnteHandle(t *testing.T) { _, err = decorator.AnteHandle(ctx, tx, false, mmd.AnteHandle) if tt.wantHasErr { - assert.Error(t, err) - assert.Contains(t, err.Error(), tt.wantErr) + require.Error(t, err) + require.Contains(t, err.Error(), tt.wantErr) } else { - assert.NoError(t, err) + require.NoError(t, err) } }) } diff --git a/changelog.md b/changelog.md index 8645d4c359..34c042c4ec 100644 --- a/changelog.md +++ b/changelog.md @@ -34,7 +34,7 @@ * [1667](https://github.com/zeta-chain/node/issues/1667) - estimate SegWit tx size in uinit of vByte ## Chores -* [1694](https://github.com/zeta-chain/node/pull/1694) - remove standalone network, use assert testing package for the entire node folder +* [1694](https://github.com/zeta-chain/node/pull/1694) - remove standalone network, use require testing package for the entire node folder ## Version: v12.1.0 diff --git a/cmd/zetacored/flags_test.go b/cmd/zetacored/flags_test.go index 993b9181f2..1fbdc4d4d0 100644 --- a/cmd/zetacored/flags_test.go +++ b/cmd/zetacored/flags_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/spf13/cobra" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" zetacore "github.com/zeta-chain/zetacore/cmd/zetacored" ) @@ -78,14 +78,14 @@ func TestReplaceFlag(t *testing.T) { err := zetacore.ReplaceFlag(tt.cmd, tt.subCommand, tt.flagName, tt.newDefaultValue) if tt.wantErr { - assert.Error(t, err) + require.Error(t, err) } else { - assert.NoError(t, err) + require.NoError(t, err) // Check if the value was replaced correctly c, _, _ := tt.cmd.Find(tt.subCommand) f := c.Flags().Lookup(tt.flagName) - assert.Equal(t, tt.expectedValue, f.DefValue) + require.Equal(t, tt.expectedValue, f.DefValue) } }) } diff --git a/cmd/zetacored/parsers_test.go b/cmd/zetacored/parsers_test.go index f3310717ef..06f0346903 100644 --- a/cmd/zetacored/parsers_test.go +++ b/cmd/zetacored/parsers_test.go @@ -6,7 +6,7 @@ import ( "os" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto" "github.com/zeta-chain/zetacore/app" @@ -18,14 +18,14 @@ func TestParsefileToObserverMapper(t *testing.T) { file := "tmp.json" defer func(t *testing.T, fp string) { err := os.RemoveAll(fp) - assert.NoError(t, err) + require.NoError(t, err) }(t, file) app.SetConfig() createObserverList(file) obsListReadFromFile, err := ParsefileToObserverDetails(file) - assert.NoError(t, err) + require.NoError(t, err) for _, obs := range obsListReadFromFile { - assert.Equal(t, obs.ZetaClientGranteeAddress, sdk.AccAddress(crypto.AddressHash([]byte("ObserverGranteeAddress"))).String()) + require.Equal(t, obs.ZetaClientGranteeAddress, sdk.AccAddress(crypto.AddressHash([]byte("ObserverGranteeAddress"))).String()) } } diff --git a/common/address_test.go b/common/address_test.go index 3e8ec1beba..af386c3bdc 100644 --- a/common/address_test.go +++ b/common/address_test.go @@ -3,7 +3,7 @@ package common import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" . "gopkg.in/check.v1" ) @@ -12,31 +12,31 @@ func TestPackage(t *testing.T) { TestingT(t) } func TestAddress(t *testing.T) { addr := NewAddress("bnb1lejrrtta9cgr49fuh7ktu3sddhe0ff7wenlpn6") - assert.EqualValuesf(t, NoAddress, addr, "address string should be empty") + require.EqualValuesf(t, NoAddress, addr, "address string should be empty") addr = NewAddress("bogus") - assert.EqualValuesf(t, NoAddress, addr, "address string should be empty") + require.EqualValuesf(t, NoAddress, addr, "address string should be empty") addr = NewAddress("0x90f2b1ae50e6018230e90a33f98c7844a0ab635a") - assert.EqualValuesf(t, "0x90f2b1ae50e6018230e90a33f98c7844a0ab635a", addr.String(), "address string should be equal") + require.EqualValuesf(t, "0x90f2b1ae50e6018230e90a33f98c7844a0ab635a", addr.String(), "address string should be equal") } func TestDecodeBtcAddress(t *testing.T) { t.Run("invalid string", func(t *testing.T) { _, err := DecodeBtcAddress("�U�ڷ���i߭����꿚�l", 18332) - assert.ErrorContains(t, err, "runtime error: index out of range") + require.ErrorContains(t, err, "runtime error: index out of range") }) t.Run("invalid chain", func(t *testing.T) { _, err := DecodeBtcAddress("14CEjTd5ci3228J45GdnGeUKLSSeCWUQxK", 0) - assert.ErrorContains(t, err, "is not a Bitcoin chain") + require.ErrorContains(t, err, "is not a Bitcoin chain") }) t.Run("nil pointer dereference", func(t *testing.T) { _, err := DecodeBtcAddress("tb1qy9pqmk2pd9sv63g27jt8r657wy0d9uee4x2dt2", 18332) - assert.ErrorContains(t, err, "runtime error: invalid memory address or nil pointer dereference") + require.ErrorContains(t, err, "runtime error: invalid memory address or nil pointer dereference") }) t.Run("valid address", func(t *testing.T) { _, err := DecodeBtcAddress("bcrt1qy9pqmk2pd9sv63g27jt8r657wy0d9uee4x2dt2", 18444) - assert.NoError(t, err) + require.NoError(t, err) }) } diff --git a/common/chain_id_test.go b/common/chain_id_test.go index 5b01d43bd9..cd4a18ca18 100644 --- a/common/chain_id_test.go +++ b/common/chain_id_test.go @@ -3,7 +3,7 @@ package common_test import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" ) @@ -48,10 +48,10 @@ func TestCosmosToEthChainID(t *testing.T) { t.Run(tc.name, func(t *testing.T) { ethChainID, err := common.CosmosToEthChainID(tc.chainID) if tc.isErr { - assert.Error(t, err) + require.Error(t, err) } else { - assert.NoError(t, err) - assert.Equal(t, tc.expected, ethChainID) + require.NoError(t, err) + require.Equal(t, tc.expected, ethChainID) } }) } diff --git a/common/chain_test.go b/common/chain_test.go index cc5795b499..f0e3c1ceed 100644 --- a/common/chain_test.go +++ b/common/chain_test.go @@ -3,7 +3,7 @@ package common import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestChain_EncodeAddress(t *testing.T) { @@ -41,18 +41,18 @@ func TestChain_EncodeAddress(t *testing.T) { t.Run(tc.name, func(t *testing.T) { s, err := tc.chain.EncodeAddress(tc.b) if tc.wantErr { - assert.Error(t, err) + require.Error(t, err) return } - assert.Equal(t, tc.want, s) + require.Equal(t, tc.want, s) }) } } func TestChain_InChainList(t *testing.T) { - assert.True(t, ZetaChainMainnet().InChainList(ZetaChainList())) - assert.True(t, ZetaMocknetChain().InChainList(ZetaChainList())) - assert.True(t, ZetaPrivnetChain().InChainList(ZetaChainList())) - assert.True(t, ZetaTestnetChain().InChainList(ZetaChainList())) - assert.False(t, EthChain().InChainList(ZetaChainList())) + require.True(t, ZetaChainMainnet().InChainList(ZetaChainList())) + require.True(t, ZetaMocknetChain().InChainList(ZetaChainList())) + require.True(t, ZetaPrivnetChain().InChainList(ZetaChainList())) + require.True(t, ZetaTestnetChain().InChainList(ZetaChainList())) + require.False(t, EthChain().InChainList(ZetaChainList())) } diff --git a/common/coin_test.go b/common/coin_test.go index 4dd03fa2db..4adfbc2d8d 100644 --- a/common/coin_test.go +++ b/common/coin_test.go @@ -4,7 +4,7 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" ) @@ -12,43 +12,43 @@ func Test_GetAzetaDecFromAmountInZeta(t *testing.T) { tt := []struct { name string zetaAmount string - err assert.ErrorAssertionFunc + err require.ErrorAssertionFunc azetaAmount sdk.Dec }{ { name: "valid zeta amount", zetaAmount: "210000000", - err: assert.NoError, + err: require.NoError, azetaAmount: sdk.MustNewDecFromStr("210000000000000000000000000"), }, { name: "very high zeta amount", zetaAmount: "21000000000000000000", - err: assert.NoError, + err: require.NoError, azetaAmount: sdk.MustNewDecFromStr("21000000000000000000000000000000000000"), }, { name: "very low zeta amount", zetaAmount: "1", - err: assert.NoError, + err: require.NoError, azetaAmount: sdk.MustNewDecFromStr("1000000000000000000"), }, { name: "zero zeta amount", zetaAmount: "0", - err: assert.NoError, + err: require.NoError, azetaAmount: sdk.MustNewDecFromStr("0"), }, { name: "decimal zeta amount", zetaAmount: "0.1", - err: assert.NoError, + err: require.NoError, azetaAmount: sdk.MustNewDecFromStr("100000000000000000"), }, { name: "invalid zeta amount", zetaAmount: "%%%%%$#", - err: assert.Error, + err: require.Error, azetaAmount: sdk.MustNewDecFromStr("0"), }, } @@ -57,7 +57,7 @@ func Test_GetAzetaDecFromAmountInZeta(t *testing.T) { azeta, err := common.GetAzetaDecFromAmountInZeta(tc.zetaAmount) tc.err(t, err) if err == nil { - assert.Equal(t, tc.azetaAmount, azeta) + require.Equal(t, tc.azetaAmount, azeta) } }) } diff --git a/common/headers_test.go b/common/headers_test.go index 9c9af29a30..2a0ed6bb74 100644 --- a/common/headers_test.go +++ b/common/headers_test.go @@ -17,7 +17,7 @@ import ( "github.com/btcsuite/btcd/wire" ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/ethclient" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" ) @@ -36,20 +36,20 @@ func TestTrueEthereumHeader(t *testing.T) { var header ethtypes.Header // read file into a byte slice file, err := os.Open("./test_data/eth_header_18495266.json") - assert.NoError(t, err) + require.NoError(t, err) defer file.Close() headerBytes := make([]byte, 4096) n, err := file.Read(headerBytes) - assert.NoError(t, err) + require.NoError(t, err) err = header.UnmarshalJSON(headerBytes[:n]) - assert.NoError(t, err) + require.NoError(t, err) var buffer bytes.Buffer err = header.EncodeRLP(&buffer) - assert.NoError(t, err) + require.NoError(t, err) headerData := common.NewEthereumHeader(buffer.Bytes()) err = headerData.Validate(header.Hash().Bytes(), 1, 18495266) - assert.NoError(t, err) + require.NoError(t, err) } func TestFalseEthereumHeader(t *testing.T) { @@ -57,22 +57,22 @@ func TestFalseEthereumHeader(t *testing.T) { var header ethtypes.Header // read file into a byte slice file, err := os.Open("./test_data/eth_header_18495266.json") - assert.NoError(t, err) + require.NoError(t, err) defer file.Close() headerBytes := make([]byte, 4096) n, err := file.Read(headerBytes) - assert.NoError(t, err) + require.NoError(t, err) err = header.UnmarshalJSON(headerBytes[:n]) - assert.NoError(t, err) + require.NoError(t, err) hash := header.Hash() header.Number = big.NewInt(18495267) var buffer bytes.Buffer err = header.EncodeRLP(&buffer) - assert.NoError(t, err) + require.NoError(t, err) headerData := common.NewEthereumHeader(buffer.Bytes()) err = headerData.Validate(hash.Bytes(), 1, 18495267) - assert.Error(t, err) + require.Error(t, err) } func TestTrueBitcoinHeader(t *testing.T) { @@ -81,7 +81,7 @@ func TestTrueBitcoinHeader(t *testing.T) { for _, b := range blocks.Blocks { // Deserialize the header bytes from base64 headerBytes, err := base64.StdEncoding.DecodeString(b.HeaderBase64) - assert.NoError(t, err) + require.NoError(t, err) header := unmarshalHeader(t, headerBytes) // Validate @@ -95,7 +95,7 @@ func TestFakeBitcoinHeader(t *testing.T) { for _, b := range blocks.Blocks { // Deserialize the header bytes from base64 headerBytes, err := base64.StdEncoding.DecodeString(b.HeaderBase64) - assert.NoError(t, err) + require.NoError(t, err) header := unmarshalHeader(t, headerBytes) // Validate @@ -106,16 +106,16 @@ func TestFakeBitcoinHeader(t *testing.T) { func BitcoinHeaderValidationLiveTest(t *testing.T) { client := createBTCClient(t) bn, err := client.GetBlockCount() - assert.NoError(t, err) + require.NoError(t, err) fmt.Printf("Verifying block headers in block range [%d, %d]\n", bn-numHeadersToTest+1, bn) for height := bn - numHeadersToTest + 1; height <= bn; height++ { blockHash, err := client.GetBlockHash(height) - assert.NoError(t, err) + require.NoError(t, err) // Get the block header header, err := client.GetBlockHeader(blockHash) - assert.NoError(t, err) + require.NoError(t, err) headerBytes := marshalHeader(t, header) // Validate true header @@ -138,7 +138,7 @@ func createBTCClient(t *testing.T) *rpcclient.Client { Params: "testnet3", } client, err := rpcclient.New(connCfg, nil) - assert.NoError(t, err) + require.NoError(t, err) return client } @@ -160,14 +160,14 @@ func copyHeader(header *wire.BlockHeader) *wire.BlockHeader { func marshalHeader(t *testing.T, header *wire.BlockHeader) []byte { var headerBuf bytes.Buffer err := header.Serialize(&headerBuf) - assert.NoError(t, err) + require.NoError(t, err) return headerBuf.Bytes() } func unmarshalHeader(t *testing.T, headerBytes []byte) *wire.BlockHeader { var header wire.BlockHeader err := header.Deserialize(bytes.NewReader(headerBytes)) - assert.NoError(t, err) + require.NoError(t, err) return &header } @@ -176,11 +176,11 @@ func validateTrueBitcoinHeader(t *testing.T, header *wire.BlockHeader, headerByt // True Bitcoin header should pass validation err := common.ValidateBitcoinHeader(headerBytes, blockHash[:], 18332) - assert.NoError(t, err) + require.NoError(t, err) // True Bitcoin header should pass timestamp validation err = common.NewBitcoinHeader(headerBytes).ValidateTimestamp(time.Now()) - assert.NoError(t, err) + require.NoError(t, err) } func validateFakeBitcoinHeader(t *testing.T, header *wire.BlockHeader, headerBytes []byte) { @@ -188,7 +188,7 @@ func validateFakeBitcoinHeader(t *testing.T, header *wire.BlockHeader, headerByt // Incorrect header length should fail validation err := common.ValidateBitcoinHeader(headerBytes[:79], blockHash[:], 18332) - assert.Error(t, err) + require.Error(t, err) // Incorrect version should fail validation fakeHeader := copyHeader(header) @@ -196,7 +196,7 @@ func validateFakeBitcoinHeader(t *testing.T, header *wire.BlockHeader, headerByt fakeBytes := marshalHeader(t, fakeHeader) fakeHash := fakeHeader.BlockHash() err = common.ValidateBitcoinHeader(fakeBytes, fakeHash[:], 18332) - assert.Error(t, err) + require.Error(t, err) // Incorrect timestamp should fail validation // Case1: timestamp is before genesis block @@ -205,23 +205,23 @@ func validateFakeBitcoinHeader(t *testing.T, header *wire.BlockHeader, headerByt fakeBytes = marshalHeader(t, fakeHeader) fakeHash = fakeHeader.BlockHash() err = common.ValidateBitcoinHeader(fakeBytes, fakeHash[:], 18332) - assert.Error(t, err) + require.Error(t, err) // Case2: timestamp is after 2 hours in the future fakeHeader = copyHeader(header) fakeHeader.Timestamp = header.Timestamp.Add(time.Second * (blockchain.MaxTimeOffsetSeconds + 1)) fakeBytes = marshalHeader(t, fakeHeader) err = common.NewBitcoinHeader(fakeBytes).ValidateTimestamp(header.Timestamp) - assert.Error(t, err) + require.Error(t, err) // Incorrect block hash should fail validation fakeHeader = copyHeader(header) header.Nonce = 0 fakeBytes = marshalHeader(t, header) err = common.ValidateBitcoinHeader(fakeBytes, blockHash[:], 18332) - assert.Error(t, err) + require.Error(t, err) // PoW not satisfied should fail validation fakeHash = fakeHeader.BlockHash() err = common.ValidateBitcoinHeader(fakeBytes, fakeHash[:], 18332) - assert.Error(t, err) + require.Error(t, err) } diff --git a/common/proof_test.go b/common/proof_test.go index d76dadbab0..0bf1244e80 100644 --- a/common/proof_test.go +++ b/common/proof_test.go @@ -10,7 +10,7 @@ import ( "encoding/json" "fmt" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" "github.com/zeta-chain/zetacore/common/bitcoin" "github.com/zeta-chain/zetacore/x/crosschain/keeper" @@ -39,21 +39,21 @@ type Blocks struct { func LoadTestBlocks(t *testing.T) Blocks { file, err := os.Open("./test_data/test_blocks.json") - assert.NoError(t, err) + require.NoError(t, err) defer file.Close() // Decode the JSON into the data struct var blocks Blocks err = json.NewDecoder(file).Decode(&blocks) - assert.NoError(t, err) + require.NoError(t, err) return blocks } func Test_IsErrorInvalidProof(t *testing.T) { - assert.False(t, common.IsErrorInvalidProof(nil)) - assert.False(t, common.IsErrorInvalidProof(errors.New("foo"))) - assert.True(t, common.IsErrorInvalidProof(common.NewErrInvalidProof(errors.New("foo")))) + require.False(t, common.IsErrorInvalidProof(nil)) + require.False(t, common.IsErrorInvalidProof(errors.New("foo"))) + require.True(t, common.IsErrorInvalidProof(common.NewErrInvalidProof(errors.New("foo")))) } func TestBitcoinMerkleProof(t *testing.T) { @@ -62,15 +62,15 @@ func TestBitcoinMerkleProof(t *testing.T) { for _, b := range blocks.Blocks { // Deserialize the header bytes from base64 headerBytes, err := base64.StdEncoding.DecodeString(b.HeaderBase64) - assert.NoError(t, err) + require.NoError(t, err) header := unmarshalHeader(t, headerBytes) // Deserialize the block bytes from base64 blockBytes, err := base64.StdEncoding.DecodeString(b.BlockBase64) - assert.NoError(t, err) + require.NoError(t, err) blockVerbose := &btcjson.GetBlockVerboseTxResult{} err = json.Unmarshal(blockBytes, blockVerbose) - assert.NoError(t, err) + require.NoError(t, err) // Validate block validateBitcoinBlock(t, header, headerBytes, blockVerbose, b.OutTxid, b.TssAddress, b.Nonce) @@ -80,23 +80,23 @@ func TestBitcoinMerkleProof(t *testing.T) { func BitcoinMerkleProofLiveTest(t *testing.T) { client := createBTCClient(t) bn, err := client.GetBlockCount() - assert.NoError(t, err) + require.NoError(t, err) fmt.Printf("Verifying transactions in block range [%d, %d]\n", bn-numBlocksToTest+1, bn) // Verify all transactions in the past 'numBlocksToTest' blocks for height := bn - numBlocksToTest + 1; height <= bn; height++ { blockHash, err := client.GetBlockHash(height) - assert.NoError(t, err) + require.NoError(t, err) // Get the block header header, err := client.GetBlockHeader(blockHash) - assert.NoError(t, err) + require.NoError(t, err) headerBytes := marshalHeader(t, header) target := blockchain.CompactToBig(header.Bits) // Get the block with verbose transactions blockVerbose, err := client.GetBlockVerboseTx(blockHash) - assert.NoError(t, err) + require.NoError(t, err) // Validate block validateBitcoinBlock(t, header, headerBytes, blockVerbose, "", "", 0) @@ -111,9 +111,9 @@ func validateBitcoinBlock(t *testing.T, _ *wire.BlockHeader, headerBytes []byte, txBodies := [][]byte{} for _, res := range blockVerbose.Tx { txBytes, err := hex.DecodeString(res.Hex) - assert.NoError(t, err) + require.NoError(t, err) tx, err := btcutil.NewTxFromBytes(txBytes) - assert.NoError(t, err) + require.NoError(t, err) // Validate Tss SegWit transaction if it's an outTx if res.Txid == outTxid { @@ -123,7 +123,7 @@ func validateBitcoinBlock(t *testing.T, _ *wire.BlockHeader, headerBytes []byte, TxHash: outTxid, } err = keeper.VerifyBTCOutTxBody(msg, txBytes, tssAddress) - assert.NoError(t, err) + require.NoError(t, err) } txns = append(txns, tx) txBodies = append(txBodies, txBytes) @@ -133,19 +133,19 @@ func validateBitcoinBlock(t *testing.T, _ *wire.BlockHeader, headerBytes []byte, mk := bitcoin.NewMerkle(txns) for i := range txns { path, index, err := mk.BuildMerkleProof(i) - assert.NoError(t, err) + require.NoError(t, err) // True proof should verify proof := common.NewBitcoinProof(txBodies[i], path, index) txBytes, err := proof.Verify(common.NewBitcoinHeader(headerBytes), 0) - assert.NoError(t, err) - assert.Equal(t, txBytes, txBodies[i]) + require.NoError(t, err) + require.Equal(t, txBytes, txBodies[i]) // Fake proof should not verify fakeIndex := index ^ 0xffffffff // flip all bits fakeProof := common.NewBitcoinProof(txBodies[i], path, fakeIndex) txBytes, err = fakeProof.Verify(common.NewBitcoinHeader(headerBytes), 0) - assert.Error(t, err) - assert.Nil(t, txBytes) + require.Error(t, err) + require.Nil(t, txBytes) } } diff --git a/testutil/keeper/crosschain.go b/testutil/keeper/crosschain.go index b6a5aa428a..69f2ae68f4 100644 --- a/testutil/keeper/crosschain.go +++ b/testutil/keeper/crosschain.go @@ -6,7 +6,7 @@ import ( "github.com/cosmos/cosmos-sdk/store" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" tmdb "github.com/tendermint/tm-db" crosschainmocks "github.com/zeta-chain/zetacore/testutil/keeper/mocks/crosschain" "github.com/zeta-chain/zetacore/x/crosschain/keeper" @@ -78,7 +78,7 @@ func CrosschainKeeperWithMocks( // Create the fungible keeper stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db) stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil) - assert.NoError(t, stateStore.LoadLatestVersion()) + require.NoError(t, stateStore.LoadLatestVersion()) ctx := NewContext(stateStore) @@ -137,30 +137,30 @@ func CrosschainKeeper(t testing.TB) (*keeper.Keeper, sdk.Context, SDKKeepers, Ze func GetCrosschainAccountMock(t testing.TB, keeper *keeper.Keeper) *crosschainmocks.CrosschainAccountKeeper { cak, ok := keeper.GetAuthKeeper().(*crosschainmocks.CrosschainAccountKeeper) - assert.True(t, ok) + require.True(t, ok) return cak } func GetCrosschainBankMock(t testing.TB, keeper *keeper.Keeper) *crosschainmocks.CrosschainBankKeeper { cbk, ok := keeper.GetBankKeeper().(*crosschainmocks.CrosschainBankKeeper) - assert.True(t, ok) + require.True(t, ok) return cbk } func GetCrosschainStakingMock(t testing.TB, keeper *keeper.Keeper) *crosschainmocks.CrosschainStakingKeeper { csk, ok := keeper.GetStakingKeeper().(*crosschainmocks.CrosschainStakingKeeper) - assert.True(t, ok) + require.True(t, ok) return csk } func GetCrosschainObserverMock(t testing.TB, keeper *keeper.Keeper) *crosschainmocks.CrosschainObserverKeeper { cok, ok := keeper.GetObserverKeeper().(*crosschainmocks.CrosschainObserverKeeper) - assert.True(t, ok) + require.True(t, ok) return cok } func GetCrosschainFungibleMock(t testing.TB, keeper *keeper.Keeper) *crosschainmocks.CrosschainFungibleKeeper { cfk, ok := keeper.GetFungibleKeeper().(*crosschainmocks.CrosschainFungibleKeeper) - assert.True(t, ok) + require.True(t, ok) return cfk } diff --git a/testutil/keeper/emissions.go b/testutil/keeper/emissions.go index 65ca6f4e5b..edcde7a75e 100644 --- a/testutil/keeper/emissions.go +++ b/testutil/keeper/emissions.go @@ -12,7 +12,7 @@ import ( bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" typesparams "github.com/cosmos/cosmos-sdk/x/params/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmdb "github.com/tendermint/tm-db" @@ -29,7 +29,7 @@ func EmissionsKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) { stateStore := store.NewCommitMultiStore(db) stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db) stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, db) - assert.NoError(t, stateStore.LoadLatestVersion()) + require.NoError(t, stateStore.LoadLatestVersion()) registry := codectypes.NewInterfaceRegistry() cdc := codec.NewProtoCodec(registry) diff --git a/testutil/keeper/fungible.go b/testutil/keeper/fungible.go index b4caebbc88..0ef4e981f4 100644 --- a/testutil/keeper/fungible.go +++ b/testutil/keeper/fungible.go @@ -8,7 +8,6 @@ import ( storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" tmdb "github.com/tendermint/tm-db" fungiblemocks "github.com/zeta-chain/zetacore/testutil/keeper/mocks/fungible" @@ -149,24 +148,24 @@ func FungibleKeeper(t testing.TB) (*keeper.Keeper, sdk.Context, SDKKeepers, Zeta func GetFungibleAccountMock(t testing.TB, keeper *keeper.Keeper) *fungiblemocks.FungibleAccountKeeper { fak, ok := keeper.GetAuthKeeper().(*fungiblemocks.FungibleAccountKeeper) - assert.True(t, ok) + require.True(t, ok) return fak } func GetFungibleBankMock(t testing.TB, keeper *keeper.Keeper) *fungiblemocks.FungibleBankKeeper { fbk, ok := keeper.GetBankKeeper().(*fungiblemocks.FungibleBankKeeper) - assert.True(t, ok) + require.True(t, ok) return fbk } func GetFungibleObserverMock(t testing.TB, keeper *keeper.Keeper) *fungiblemocks.FungibleObserverKeeper { fok, ok := keeper.GetObserverKeeper().(*fungiblemocks.FungibleObserverKeeper) - assert.True(t, ok) + require.True(t, ok) return fok } func GetFungibleEVMMock(t testing.TB, keeper *keeper.Keeper) *fungiblemocks.FungibleEVMKeeper { fek, ok := keeper.GetEVMKeeper().(*fungiblemocks.FungibleEVMKeeper) - assert.True(t, ok) + require.True(t, ok) return fek } diff --git a/testutil/keeper/observer.go b/testutil/keeper/observer.go index 0d2395af70..946dac84c6 100644 --- a/testutil/keeper/observer.go +++ b/testutil/keeper/observer.go @@ -11,7 +11,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" tmdb "github.com/tendermint/tm-db" "github.com/zeta-chain/zetacore/x/observer/keeper" "github.com/zeta-chain/zetacore/x/observer/types" @@ -56,7 +56,7 @@ func ObserverKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) { // Create the observer keeper stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db) stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil) - assert.NoError(t, stateStore.LoadLatestVersion()) + require.NoError(t, stateStore.LoadLatestVersion()) ctx := NewContext(stateStore) diff --git a/testutil/network/genesis_state.go b/testutil/network/genesis_state.go index d74b5c4c8f..12ae9f9d50 100644 --- a/testutil/network/genesis_state.go +++ b/testutil/network/genesis_state.go @@ -10,7 +10,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" evmtypes "github.com/evmos/ethermint/x/evm/types" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" cmdcfg "github.com/zeta-chain/zetacore/cmd/zetacored/config" "github.com/zeta-chain/zetacore/common" "github.com/zeta-chain/zetacore/testutil/nullify" @@ -22,7 +22,7 @@ func SetupZetaGenesisState(t *testing.T, genesisState map[string]json.RawMessage // Cross-chain genesis state var crossChainGenesis types.GenesisState - assert.NoError(t, codec.UnmarshalJSON(genesisState[types.ModuleName], &crossChainGenesis)) + require.NoError(t, codec.UnmarshalJSON(genesisState[types.ModuleName], &crossChainGenesis)) nodeAccountList := make([]*observertypes.NodeAccount, len(observerList)) for i, operator := range observerList { nodeAccountList[i] = &observertypes.NodeAccount{ @@ -32,28 +32,28 @@ func SetupZetaGenesisState(t *testing.T, genesisState map[string]json.RawMessage } crossChainGenesis.Params.Enabled = true - assert.NoError(t, crossChainGenesis.Validate()) + require.NoError(t, crossChainGenesis.Validate()) crossChainGenesisBz, err := codec.MarshalJSON(&crossChainGenesis) - assert.NoError(t, err) + require.NoError(t, err) // EVM genesis state var evmGenesisState evmtypes.GenesisState - assert.NoError(t, codec.UnmarshalJSON(genesisState[evmtypes.ModuleName], &evmGenesisState)) + require.NoError(t, codec.UnmarshalJSON(genesisState[evmtypes.ModuleName], &evmGenesisState)) evmGenesisState.Params.EvmDenom = cmdcfg.BaseDenom - assert.NoError(t, evmGenesisState.Validate()) + require.NoError(t, evmGenesisState.Validate()) evmGenesisBz, err := codec.MarshalJSON(&evmGenesisState) - assert.NoError(t, err) + require.NoError(t, err) // Staking genesis state var stakingGenesisState stakingtypes.GenesisState - assert.NoError(t, codec.UnmarshalJSON(genesisState[stakingtypes.ModuleName], &stakingGenesisState)) + require.NoError(t, codec.UnmarshalJSON(genesisState[stakingtypes.ModuleName], &stakingGenesisState)) stakingGenesisState.Params.BondDenom = cmdcfg.BaseDenom stakingGenesisStateBz, err := codec.MarshalJSON(&stakingGenesisState) - assert.NoError(t, err) + require.NoError(t, err) // Observer genesis state var observerGenesis observertypes.GenesisState - assert.NoError(t, codec.UnmarshalJSON(genesisState[observertypes.ModuleName], &observerGenesis)) + require.NoError(t, codec.UnmarshalJSON(genesisState[observertypes.ModuleName], &observerGenesis)) observerSet := observertypes.ObserverSet{ ObserverList: observerList, } @@ -92,9 +92,9 @@ func SetupZetaGenesisState(t *testing.T, genesisState map[string]json.RawMessage IsInboundEnabled: true, IsOutboundEnabled: true, } - assert.NoError(t, observerGenesis.Validate()) + require.NoError(t, observerGenesis.Validate()) observerGenesisBz, err := codec.MarshalJSON(&observerGenesis) - assert.NoError(t, err) + require.NoError(t, err) genesisState[types.ModuleName] = crossChainGenesisBz genesisState[stakingtypes.ModuleName] = stakingGenesisStateBz @@ -104,7 +104,7 @@ func SetupZetaGenesisState(t *testing.T, genesisState map[string]json.RawMessage func AddObserverData(t *testing.T, n int, genesisState map[string]json.RawMessage, codec codec.Codec, ballots []*observertypes.Ballot) *observertypes.GenesisState { state := observertypes.GenesisState{} - assert.NoError(t, codec.UnmarshalJSON(genesisState[observertypes.ModuleName], &state)) + require.NoError(t, codec.UnmarshalJSON(genesisState[observertypes.ModuleName], &state)) // set chain params with chains all enabled state.ChainParamsList = observertypes.GetDefaultChainParams() @@ -155,17 +155,17 @@ func AddObserverData(t *testing.T, n int, genesisState map[string]json.RawMessag } // check genesis state validity - assert.NoError(t, state.Validate()) + require.NoError(t, state.Validate()) // marshal genesis state buf, err := codec.MarshalJSON(&state) - assert.NoError(t, err) + require.NoError(t, err) genesisState[observertypes.ModuleName] = buf return &state } func AddCrosschainData(t *testing.T, n int, genesisState map[string]json.RawMessage, codec codec.Codec) *types.GenesisState { state := types.GenesisState{} - assert.NoError(t, codec.UnmarshalJSON(genesisState[types.ModuleName], &state)) + require.NoError(t, codec.UnmarshalJSON(genesisState[types.ModuleName], &state)) // TODO : Fix add EVM balance to deploy contracts for i := 0; i < n; i++ { state.CrossChainTxs = append(state.CrossChainTxs, &types.CrossChainTx{ @@ -216,10 +216,10 @@ func AddCrosschainData(t *testing.T, n int, genesisState map[string]json.RawMess state.OutTxTrackerList = append(state.OutTxTrackerList, outTxTracker) } - assert.NoError(t, state.Validate()) + require.NoError(t, state.Validate()) buf, err := codec.MarshalJSON(&state) - assert.NoError(t, err) + require.NoError(t, err) genesisState[types.ModuleName] = buf return &state } diff --git a/testutil/sample/sample.go b/testutil/sample/sample.go index a6f2a3aeac..4fcc9ac9e8 100644 --- a/testutil/sample/sample.go +++ b/testutil/sample/sample.go @@ -15,7 +15,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ethcommon "github.com/ethereum/go-ethereum/common" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" "github.com/zeta-chain/zetacore/common/cosmos" ) @@ -30,7 +30,7 @@ func newRandFromSeed(s int64) *rand.Rand { func newRandFromStringSeed(t *testing.T, s string) *rand.Rand { h := fnv.New64a() _, err := h.Write([]byte(s)) - assert.NoError(t, err) + require.NoError(t, err) return newRandFromSeed(int64(h.Sum64())) } @@ -70,7 +70,7 @@ func Validator(t testing.TB, r *rand.Rand) stakingtypes.Validator { ValAddress(r), ed25519.GenPrivKeyFromSecret(seed).PubKey(), stakingtypes.Description{}) - assert.NoError(t, err) + require.NoError(t, err) return val } diff --git a/testutil/sample/sample_test.go b/testutil/sample/sample_test.go index b940760e03..3cd0687c08 100644 --- a/testutil/sample/sample_test.go +++ b/testutil/sample/sample_test.go @@ -4,14 +4,14 @@ import ( "testing" ethcommon "github.com/ethereum/go-ethereum/common" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestEthAddress(t *testing.T) { ethAddress := EthAddress() - assert.NotEqual(t, ethcommon.Address{}, ethAddress) + require.NotEqual(t, ethcommon.Address{}, ethAddress) // don't generate the same address ethAddress2 := EthAddress() - assert.NotEqual(t, ethAddress, ethAddress2) + require.NotEqual(t, ethAddress, ethAddress2) } diff --git a/testutil/simapp/simapp.go b/testutil/simapp/simapp.go index cb3766e7e9..cde89abbab 100644 --- a/testutil/simapp/simapp.go +++ b/testutil/simapp/simapp.go @@ -12,7 +12,7 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmtypes "github.com/tendermint/tendermint/types" "github.com/zeta-chain/zetacore/cmd/zetacored/config" @@ -70,9 +70,9 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genDelAc // Make all members of delSet as delegators to each of the validators for _, val := range valSet.Validators { pk, err := cryptocodec.FromTmPubKeyInterface(val.PubKey) - assert.NoError(t, err) + require.NoError(t, err) pkAny, err := codectypes.NewAnyWithValue(pk) - assert.NoError(t, err) + require.NoError(t, err) validator := stakingtypes.Validator{ OperatorAddress: sdk.ValAddress(val.Address).String(), ConsensusPubkey: pkAny, @@ -127,7 +127,7 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genDelAc genesisState[banktypes.ModuleName] = app.AppCodec().MustMarshalJSON(bankGenesis) stateBytes, err := json.MarshalIndent(genesisState, "", " ") - assert.NoError(t, err) + require.NoError(t, err) // init chain will set the validator set and initialize the genesis accounts app.InitChain( diff --git a/x/crosschain/client/cli/cli_out_tx_tracker_test.go b/x/crosschain/client/cli/cli_out_tx_tracker_test.go index 7346e573c5..01976193dc 100644 --- a/x/crosschain/client/cli/cli_out_tx_tracker_test.go +++ b/x/crosschain/client/cli/cli_out_tx_tracker_test.go @@ -4,7 +4,7 @@ import ( "fmt" "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/app" "github.com/zeta-chain/zetacore/testutil/network" "github.com/zeta-chain/zetacore/testutil/nullify" @@ -15,7 +15,7 @@ func networkWithOutTxTrackerObjects(t *testing.T, n int) (*network.Network, []ty t.Helper() cfg := network.DefaultConfig() state := types.GenesisState{} - assert.NoError(t, cfg.Codec.UnmarshalJSON(cfg.GenesisState[types.ModuleName], &state)) + require.NoError(t, cfg.Codec.UnmarshalJSON(cfg.GenesisState[types.ModuleName], &state)) for i := 0; i < n; i++ { outTxTracker := types.OutTxTracker{ @@ -25,7 +25,7 @@ func networkWithOutTxTrackerObjects(t *testing.T, n int) (*network.Network, []ty state.OutTxTrackerList = append(state.OutTxTrackerList, outTxTracker) } buf, err := cfg.Codec.MarshalJSON(&state) - assert.NoError(t, err) + require.NoError(t, err) cfg.GenesisState[types.ModuleName] = buf //cfg.GenesisState = network.SetupZetaGenesisState(t, cfg.GenesisState, cfg.Codec) net, err := network.New(t, app.NodeDir, cfg) @@ -72,14 +72,14 @@ func networkWithOutTxTrackerObjects(t *testing.T, n int) (*network.Network, []ty // out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdShowOutTxTracker(), args) // if tc.err != nil { // stat, ok := status.FromError(tc.err) -// assert.True(t, ok) -// assert.ErrorIs(t, stat.Err(), tc.err) +// require.True(t, ok) +// require.ErrorIs(t, stat.Err(), tc.err) // } else { -// assert.NoError(t, err) +// require.NoError(t, err) // var resp types.QueryGetOutTxTrackerResponse -// assert.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) -// assert.NotNil(t, resp.OutTxTracker) -// assert.Equal(t, +// require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) +// require.NotNil(t, resp.OutTxTracker) +// require.Equal(t, // nullify.Fill(&tc.obj), // nullify.Fill(&resp.OutTxTracker), // ) @@ -112,11 +112,11 @@ func networkWithOutTxTrackerObjects(t *testing.T, n int) (*network.Network, []ty // for i := 0; i < len(objs); i += step { // args := request(nil, uint64(i), uint64(step), false) // out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdListOutTxTracker(), args) -// assert.NoError(t, err) +// require.NoError(t, err) // var resp types.QueryAllOutTxTrackerResponse -// assert.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) -// assert.LessOrEqual(t, len(resp.OutTxTracker), step) -// assert.Subset(t, +// require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) +// require.LessOrEqual(t, len(resp.OutTxTracker), step) +// require.Subset(t, // nullify.Fill(objs), // nullify.Fill(resp.OutTxTracker), // ) @@ -128,11 +128,11 @@ func networkWithOutTxTrackerObjects(t *testing.T, n int) (*network.Network, []ty // for i := 0; i < len(objs); i += step { // args := request(next, 0, uint64(step), false) // out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdListOutTxTracker(), args) -// assert.NoError(t, err) +// require.NoError(t, err) // var resp types.QueryAllOutTxTrackerResponse -// assert.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) -// assert.LessOrEqual(t, len(resp.OutTxTracker), step) -// assert.Subset(t, +// require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) +// require.LessOrEqual(t, len(resp.OutTxTracker), step) +// require.Subset(t, // nullify.Fill(objs), // nullify.Fill(resp.OutTxTracker), // ) @@ -142,12 +142,12 @@ func networkWithOutTxTrackerObjects(t *testing.T, n int) (*network.Network, []ty // t.Run("Total", func(t *testing.T) { // args := request(nil, 0, uint64(len(objs)), true) // out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdListOutTxTracker(), args) -// assert.NoError(t, err) +// require.NoError(t, err) // var resp types.QueryAllOutTxTrackerResponse -// assert.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) -// assert.NoError(t, err) -// assert.Equal(t, len(objs), int(resp.Pagination.Total)) -// assert.ElementsMatch(t, +// require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) +// require.NoError(t, err) +// require.Equal(t, len(objs), int(resp.Pagination.Total)) +// require.ElementsMatch(t, // nullify.Fill(objs), // nullify.Fill(resp.OutTxTracker), // ) diff --git a/x/crosschain/client/integrationtests/cli_helpers.go b/x/crosschain/client/integrationtests/cli_helpers.go index ec9465d48e..3195782031 100644 --- a/x/crosschain/client/integrationtests/cli_helpers.go +++ b/x/crosschain/client/integrationtests/cli_helpers.go @@ -15,7 +15,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" authcli "github.com/cosmos/cosmos-sdk/x/auth/client/cli" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" tmcli "github.com/tendermint/tendermint/libs/cli" "github.com/zeta-chain/zetacore/common" "github.com/zeta-chain/zetacore/testutil/network" @@ -44,7 +44,7 @@ func WriteToNewTempFile(t testing.TB, s string) *os.File { fp := TempFile(t) _, err := fp.WriteString(s) - assert.Nil(t, err) + require.Nil(t, err) return fp } @@ -54,7 +54,7 @@ func TempFile(t testing.TB) *os.File { t.Helper() fp, err := os.CreateTemp(GetTempDir(t), "") - assert.NoError(t, err) + require.NoError(t, err) return fp } @@ -67,10 +67,10 @@ func GetTempDir(t testing.TB) string { // https://github.com/cosmos/cosmos-sdk/pull/10341 for // this change's rationale. tempdir, err := os.MkdirTemp("", "") - assert.NoError(t, err) + require.NoError(t, err) t.Cleanup(func() { err := os.RemoveAll(tempdir) - assert.NoError(t, err) + require.NoError(t, err) }) return tempdir } @@ -86,11 +86,11 @@ func BuildSignedDeploySystemContract(t testing.TB, val *network.Validator, denom fmt.Sprintf("--%s=%d", flags.FlagGas, 4000000), } out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, txArgs) - assert.NoError(t, err) + require.NoError(t, err) unsignerdTx := WriteToNewTempFile(t, out.String()) res, err := TxSignExec(val.ClientCtx, val.Address, unsignerdTx.Name(), "--offline", "--account-number", strconv.FormatUint(account.GetAccountNumber(), 10), "--sequence", strconv.FormatUint(account.GetSequence(), 10)) - assert.NoError(t, err) + require.NoError(t, err) return WriteToNewTempFile(t, res.String()) } @@ -112,11 +112,11 @@ func BuildSignedUpdateSystemContract( } args := append([]string{systemContractAddress}, txArgs...) out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args) - assert.NoError(t, err) + require.NoError(t, err) unsignerdTx := WriteToNewTempFile(t, out.String()) res, err := TxSignExec(val.ClientCtx, val.Address, unsignerdTx.Name(), "--offline", "--account-number", strconv.FormatUint(account.GetAccountNumber(), 10), "--sequence", strconv.FormatUint(account.GetSequence(), 10)) - assert.NoError(t, err) + require.NoError(t, err) return WriteToNewTempFile(t, res.String()) } @@ -145,11 +145,11 @@ func BuildSignedDeployETHZRC20( "1000000", }, txArgs...) out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args) - assert.NoError(t, err) + require.NoError(t, err) unsignerdTx := WriteToNewTempFile(t, out.String()) res, err := TxSignExec(val.ClientCtx, val.Address, unsignerdTx.Name(), "--offline", "--account-number", strconv.FormatUint(account.GetAccountNumber(), 10), "--sequence", strconv.FormatUint(account.GetSequence(), 10)) - assert.NoError(t, err) + require.NoError(t, err) return WriteToNewTempFile(t, res.String()) } @@ -171,11 +171,11 @@ func BuildSignedGasPriceVote(t testing.TB, val *network.Validator, denom string, } args := append(inboundVoterArgs, txArgs...) out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args) - assert.NoError(t, err) + require.NoError(t, err) unsignerdTx := WriteToNewTempFile(t, out.String()) res, err := TxSignExec(val.ClientCtx, val.Address, unsignerdTx.Name(), "--offline", "--account-number", strconv.FormatUint(account.GetAccountNumber(), 10), "--sequence", strconv.FormatUint(account.GetSequence(), 10)) - assert.NoError(t, err) + require.NoError(t, err) return WriteToNewTempFile(t, res.String()) } @@ -196,11 +196,11 @@ func BuildSignedTssVote(t testing.TB, val *network.Validator, denom string, acco } args := append(inboundVoterArgs, txArgs...) out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args) - assert.NoError(t, err) + require.NoError(t, err) unsignerdTx := WriteToNewTempFile(t, out.String()) res, err := TxSignExec(val.ClientCtx, val.Address, unsignerdTx.Name(), "--offline", "--account-number", strconv.FormatUint(account.GetAccountNumber(), 10), "--sequence", strconv.FormatUint(account.GetSequence(), 10)) - assert.NoError(t, err) + require.NoError(t, err) return WriteToNewTempFile(t, res.String()) } @@ -239,12 +239,12 @@ func BuildSignedOutboundVote( } args := append(outboundVoterArgs, txArgs...) out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args) - assert.NoError(t, err) + require.NoError(t, err) unsignerdTx := WriteToNewTempFile(t, out.String()) res, err := TxSignExec(val.ClientCtx, val.Address, unsignerdTx.Name(), "--offline", "--account-number", strconv.FormatUint(account.GetAccountNumber(), 10), "--sequence", strconv.FormatUint(account.GetSequence(), 10)) - assert.NoError(t, err) + require.NoError(t, err) return WriteToNewTempFile(t, res.String()) } @@ -274,11 +274,11 @@ func BuildSignedInboundVote(t testing.TB, val *network.Validator, denom string, } args := append(inboundVoterArgs, txArgs...) out, err := clitestutil.ExecTestCLICmd(val.ClientCtx, cmd, args) - assert.NoError(t, err) + require.NoError(t, err) unsignerdTx := WriteToNewTempFile(t, out.String()) res, err := TxSignExec(val.ClientCtx, val.Address, unsignerdTx.Name(), "--offline", "--account-number", strconv.FormatUint(account.GetAccountNumber(), 10), "--sequence", strconv.FormatUint(account.GetSequence(), 10)) - assert.NoError(t, err) + require.NoError(t, err) return WriteToNewTempFile(t, res.String()) } diff --git a/x/crosschain/genesis_test.go b/x/crosschain/genesis_test.go index 052e075108..3ce6a94875 100644 --- a/x/crosschain/genesis_test.go +++ b/x/crosschain/genesis_test.go @@ -3,7 +3,7 @@ package crosschain_test import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/nullify" "github.com/zeta-chain/zetacore/testutil/sample" @@ -46,10 +46,10 @@ func TestGenesis(t *testing.T) { k, ctx, _, _ := keepertest.CrosschainKeeper(t) crosschain.InitGenesis(ctx, *k, genesisState) got := crosschain.ExportGenesis(ctx, *k) - assert.NotNil(t, got) + require.NotNil(t, got) // Compare genesis after init and export nullify.Fill(&genesisState) nullify.Fill(got) - assert.Equal(t, genesisState, *got) + require.Equal(t, genesisState, *got) } diff --git a/x/crosschain/keeper/abci_test.go b/x/crosschain/keeper/abci_test.go index 93c021da8a..ea46e70dc4 100644 --- a/x/crosschain/keeper/abci_test.go +++ b/x/crosschain/keeper/abci_test.go @@ -8,7 +8,7 @@ import ( "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" testkeeper "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -64,8 +64,8 @@ func TestKeeper_IterateAndUpdateCctxGasPrice(t *testing.T) { ctx = ctx.WithBlockHeight(observertypes.DefaultCrosschainFlags().GasPriceIncreaseFlags.EpochLength + 1) cctxCount, flags := k.IterateAndUpdateCctxGasPrice(ctx, supportedChains, updateFunc) - assert.Equal(t, 0, cctxCount) - assert.Equal(t, *observertypes.DefaultCrosschainFlags().GasPriceIncreaseFlags, flags) + require.Equal(t, 0, cctxCount) + require.Equal(t, *observertypes.DefaultCrosschainFlags().GasPriceIncreaseFlags, flags) // test that custom crosschain flags are used when set and the epoch length is reached customFlags := observertypes.GasPriceIncreaseFlags{ @@ -80,8 +80,8 @@ func TestKeeper_IterateAndUpdateCctxGasPrice(t *testing.T) { zk.ObserverKeeper.SetCrosschainFlags(ctx, *crosschainFlags) cctxCount, flags = k.IterateAndUpdateCctxGasPrice(ctx, supportedChains, updateFunc) - assert.Equal(t, 0, cctxCount) - assert.Equal(t, customFlags, flags) + require.Equal(t, 0, cctxCount) + require.Equal(t, customFlags, flags) // test that cctx are iterated and updated when the epoch length is reached @@ -89,19 +89,19 @@ func TestKeeper_IterateAndUpdateCctxGasPrice(t *testing.T) { cctxCount, flags = k.IterateAndUpdateCctxGasPrice(ctx, supportedChains, updateFunc) // 2 eth + 5 bsc = 7 - assert.Equal(t, 7, cctxCount) - assert.Equal(t, customFlags, flags) + require.Equal(t, 7, cctxCount) + require.Equal(t, customFlags, flags) // check that the update function was called with the cctx index - assert.Equal(t, 7, len(updateFuncMap)) - assert.Contains(t, updateFuncMap, "1-10") - assert.Contains(t, updateFuncMap, "1-11") + require.Equal(t, 7, len(updateFuncMap)) + require.Contains(t, updateFuncMap, "1-10") + require.Contains(t, updateFuncMap, "1-11") - assert.Contains(t, updateFuncMap, "56-30") - assert.Contains(t, updateFuncMap, "56-31") - assert.Contains(t, updateFuncMap, "56-32") - assert.Contains(t, updateFuncMap, "56-33") - assert.Contains(t, updateFuncMap, "56-34") + require.Contains(t, updateFuncMap, "56-30") + require.Contains(t, updateFuncMap, "56-31") + require.Contains(t, updateFuncMap, "56-32") + require.Contains(t, updateFuncMap, "56-33") + require.Contains(t, updateFuncMap, "56-34") } func TestCheckAndUpdateCctxGasPrice(t *testing.T) { @@ -360,8 +360,8 @@ func TestCheckAndUpdateCctxGasPrice(t *testing.T) { // ensure median gas price is set medianGasPrice, isFound := k.GetMedianGasPriceInUint(ctx, chainID) - assert.True(t, isFound) - assert.True(t, medianGasPrice.Equal(math.NewUint(tc.medianGasPrice))) + require.True(t, isFound) + require.True(t, medianGasPrice.Equal(math.NewUint(tc.medianGasPrice))) } // set block timestamp @@ -377,23 +377,23 @@ func TestCheckAndUpdateCctxGasPrice(t *testing.T) { gasPriceIncrease, feesPaid, err := keeper.CheckAndUpdateCctxGasPrice(ctx, *k, tc.cctx, tc.flags) if tc.isError { - assert.Error(t, err) + require.Error(t, err) return } - assert.NoError(t, err) + require.NoError(t, err) // check values - assert.True(t, gasPriceIncrease.Equal(tc.expectedGasPriceIncrease), "expected %s, got %s", tc.expectedGasPriceIncrease.String(), gasPriceIncrease.String()) - assert.True(t, feesPaid.Equal(tc.expectedAdditionalFees), "expected %s, got %s", tc.expectedAdditionalFees.String(), feesPaid.String()) + require.True(t, gasPriceIncrease.Equal(tc.expectedGasPriceIncrease), "expected %s, got %s", tc.expectedGasPriceIncrease.String(), gasPriceIncrease.String()) + require.True(t, feesPaid.Equal(tc.expectedAdditionalFees), "expected %s, got %s", tc.expectedAdditionalFees.String(), feesPaid.String()) // check cctx if !tc.expectedGasPriceIncrease.IsZero() { cctx, found := k.GetCrossChainTx(ctx, tc.cctx.Index) - assert.True(t, found) + require.True(t, found) newGasPrice, err := cctx.GetCurrentOutTxParam().GetGasPrice() - assert.NoError(t, err) - assert.EqualValues(t, tc.expectedGasPriceIncrease.AddUint64(previousGasPrice).Uint64(), newGasPrice, "%d - %d", tc.expectedGasPriceIncrease.Uint64(), previousGasPrice) - assert.EqualValues(t, tc.blockTimestamp.Unix(), cctx.CctxStatus.LastUpdateTimestamp) + require.NoError(t, err) + require.EqualValues(t, tc.expectedGasPriceIncrease.AddUint64(previousGasPrice).Uint64(), newGasPrice, "%d - %d", tc.expectedGasPriceIncrease.Uint64(), previousGasPrice) + require.EqualValues(t, tc.blockTimestamp.Unix(), cctx.CctxStatus.LastUpdateTimestamp) } }) } diff --git a/x/crosschain/keeper/cctx_test.go b/x/crosschain/keeper/cctx_test.go index 764ce660d9..6732ed6795 100644 --- a/x/crosschain/keeper/cctx_test.go +++ b/x/crosschain/keeper/cctx_test.go @@ -7,7 +7,7 @@ import ( "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/types/query" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/crosschain/keeper" @@ -123,14 +123,14 @@ func TestSends(t *testing.T) { sends = append(sends, createNCctxWithStatus(keeper, ctx, tt.Aborted, types.CctxStatus_Aborted)...) sends = append(sends, createNCctxWithStatus(keeper, ctx, tt.OutboundMined, types.CctxStatus_OutboundMined)...) sends = append(sends, createNCctxWithStatus(keeper, ctx, tt.Reverted, types.CctxStatus_Reverted)...) - //assert.Equal(t, tt.PendingOutbound, len(keeper.GetAllCctxByStatuses(ctx, []types.CctxStatus{types.CctxStatus_PendingOutbound}))) - //assert.Equal(t, tt.PendingInbound, len(keeper.GetAllCctxByStatuses(ctx, []types.CctxStatus{types.CctxStatus_PendingInbound}))) - //assert.Equal(t, tt.PendingOutbound+tt.PendingRevert, len(keeper.GetAllCctxByStatuses(ctx, []types.CctxStatus{types.CctxStatus_PendingOutbound, types.CctxStatus_PendingRevert}))) - assert.Equal(t, len(sends), len(keeper.GetAllCrossChainTx(ctx))) + //require.Equal(t, tt.PendingOutbound, len(keeper.GetAllCctxByStatuses(ctx, []types.CctxStatus{types.CctxStatus_PendingOutbound}))) + //require.Equal(t, tt.PendingInbound, len(keeper.GetAllCctxByStatuses(ctx, []types.CctxStatus{types.CctxStatus_PendingInbound}))) + //require.Equal(t, tt.PendingOutbound+tt.PendingRevert, len(keeper.GetAllCctxByStatuses(ctx, []types.CctxStatus{types.CctxStatus_PendingOutbound, types.CctxStatus_PendingRevert}))) + require.Equal(t, len(sends), len(keeper.GetAllCrossChainTx(ctx))) for _, s := range sends { send, found := keeper.GetCrossChainTx(ctx, s.Index) - assert.True(t, found) - assert.Equal(t, s, send) + require.True(t, found) + require.Equal(t, s, send) } }) @@ -146,7 +146,7 @@ func TestSendGetAll(t *testing.T) { for i, val := range cctx { c[i] = val } - assert.Equal(t, items, c) + require.Equal(t, items, c) } // Querier Tests @@ -186,9 +186,9 @@ func TestSendQuerySingle(t *testing.T) { t.Run(tc.desc, func(t *testing.T) { response, err := keeper.Cctx(wctx, tc.request) if tc.err != nil { - assert.ErrorIs(t, err, tc.err) + require.ErrorIs(t, err, tc.err) } else { - assert.Equal(t, tc.response, response) + require.Equal(t, tc.response, response) } }) } @@ -214,9 +214,9 @@ func TestSendQueryPaginated(t *testing.T) { step := 2 for i := 0; i < len(msgs); i += step { resp, err := keeper.CctxAll(wctx, request(nil, uint64(i), uint64(step), false)) - assert.NoError(t, err) + require.NoError(t, err) for j := i; j < len(msgs) && j < i+step; j++ { - assert.Equal(t, &msgs[j], resp.CrossChainTx[j-i]) + require.Equal(t, &msgs[j], resp.CrossChainTx[j-i]) } } }) @@ -225,20 +225,20 @@ func TestSendQueryPaginated(t *testing.T) { var next []byte for i := 0; i < len(msgs); i += step { resp, err := keeper.CctxAll(wctx, request(next, 0, uint64(step), false)) - assert.NoError(t, err) + require.NoError(t, err) for j := i; j < len(msgs) && j < i+step; j++ { - assert.Equal(t, &msgs[j], resp.CrossChainTx[j-i]) + require.Equal(t, &msgs[j], resp.CrossChainTx[j-i]) } next = resp.Pagination.NextKey } }) t.Run("Total", func(t *testing.T) { resp, err := keeper.CctxAll(wctx, request(nil, 0, 0, true)) - assert.NoError(t, err) - assert.Equal(t, len(msgs), int(resp.Pagination.Total)) + require.NoError(t, err) + require.Equal(t, len(msgs), int(resp.Pagination.Total)) }) t.Run("InvalidRequest", func(t *testing.T) { _, err := keeper.CctxAll(wctx, nil) - assert.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) + require.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) }) } diff --git a/x/crosschain/keeper/cctx_utils_test.go b/x/crosschain/keeper/cctx_utils_test.go index 27c1509ffb..2d122bce7a 100644 --- a/x/crosschain/keeper/cctx_utils_test.go +++ b/x/crosschain/keeper/cctx_utils_test.go @@ -6,7 +6,7 @@ import ( "cosmossdk.io/math" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -44,12 +44,12 @@ func TestKeeper_RefundAmountOnZetaChain(t *testing.T) { }}, math.NewUint(42), ) - assert.NoError(t, err) + require.NoError(t, err) // check amount deposited in balance balance, err := zk.FungibleKeeper.BalanceOfZRC4(ctx, zrc20Addr, sender) - assert.NoError(t, err) - assert.Equal(t, uint64(42), balance.Uint64()) + require.NoError(t, err) + require.Equal(t, uint64(42), balance.Uint64()) // can refund again err = k.RefundAmountOnZetaChain(ctx, types.CrossChainTx{ @@ -61,10 +61,10 @@ func TestKeeper_RefundAmountOnZetaChain(t *testing.T) { }}, math.NewUint(42), ) - assert.NoError(t, err) + require.NoError(t, err) balance, err = zk.FungibleKeeper.BalanceOfZRC4(ctx, zrc20Addr, sender) - assert.NoError(t, err) - assert.Equal(t, uint64(84), balance.Uint64()) + require.NoError(t, err) + require.Equal(t, uint64(84), balance.Uint64()) }) t.Run("should fail with invalid cctx", func(t *testing.T) { @@ -76,7 +76,7 @@ func TestKeeper_RefundAmountOnZetaChain(t *testing.T) { }}, math.NewUint(42), ) - assert.ErrorContains(t, err, "unsupported coin type") + require.ErrorContains(t, err, "unsupported coin type") err = k.RefundAmountOnZetaChain(ctx, types.CrossChainTx{ InboundTxParams: &types.InboundTxParams{ @@ -84,7 +84,7 @@ func TestKeeper_RefundAmountOnZetaChain(t *testing.T) { }}, math.NewUint(42), ) - assert.ErrorContains(t, err, "unsupported coin type") + require.ErrorContains(t, err, "unsupported coin type") err = k.RefundAmountOnZetaChain(ctx, types.CrossChainTx{ InboundTxParams: &types.InboundTxParams{ @@ -93,7 +93,7 @@ func TestKeeper_RefundAmountOnZetaChain(t *testing.T) { }}, math.NewUint(42), ) - assert.ErrorContains(t, err, "only EVM chains are supported") + require.ErrorContains(t, err, "only EVM chains are supported") err = k.RefundAmountOnZetaChain(ctx, types.CrossChainTx{ InboundTxParams: &types.InboundTxParams{ @@ -103,7 +103,7 @@ func TestKeeper_RefundAmountOnZetaChain(t *testing.T) { }}, math.NewUint(42), ) - assert.ErrorContains(t, err, "invalid sender address") + require.ErrorContains(t, err, "invalid sender address") err = k.RefundAmountOnZetaChain(ctx, types.CrossChainTx{ InboundTxParams: &types.InboundTxParams{ @@ -114,7 +114,7 @@ func TestKeeper_RefundAmountOnZetaChain(t *testing.T) { }, math.Uint{}, ) - assert.ErrorContains(t, err, "no amount to refund") + require.ErrorContains(t, err, "no amount to refund") err = k.RefundAmountOnZetaChain(ctx, types.CrossChainTx{ InboundTxParams: &types.InboundTxParams{ @@ -124,7 +124,7 @@ func TestKeeper_RefundAmountOnZetaChain(t *testing.T) { }}, math.ZeroUint(), ) - assert.ErrorContains(t, err, "no amount to refund") + require.ErrorContains(t, err, "no amount to refund") // the foreign coin has not been set err = k.RefundAmountOnZetaChain(ctx, types.CrossChainTx{ @@ -136,7 +136,7 @@ func TestKeeper_RefundAmountOnZetaChain(t *testing.T) { }}, math.NewUint(42), ) - assert.ErrorContains(t, err, "zrc not found") + require.ErrorContains(t, err, "zrc not found") }) } @@ -145,8 +145,8 @@ func TestGetRevertGasLimit(t *testing.T) { k, ctx, _, _ := keepertest.CrosschainKeeper(t) gasLimit, err := k.GetRevertGasLimit(ctx, types.CrossChainTx{}) - assert.NoError(t, err) - assert.Equal(t, uint64(0), gasLimit) + require.NoError(t, err) + require.Equal(t, uint64(0), gasLimit) }) t.Run("should return 0 if coin type is not gas or erc20", func(t *testing.T) { @@ -156,8 +156,8 @@ func TestGetRevertGasLimit(t *testing.T) { InboundTxParams: &types.InboundTxParams{ CoinType: common.CoinType_Zeta, }}) - assert.NoError(t, err) - assert.Equal(t, uint64(0), gasLimit) + require.NoError(t, err) + require.Equal(t, uint64(0), gasLimit) }) t.Run("should return the gas limit of the gas token", func(t *testing.T) { @@ -169,15 +169,15 @@ func TestGetRevertGasLimit(t *testing.T) { gas := setupGasCoin(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper, chainID, "foo", "FOO") _, err := zk.FungibleKeeper.UpdateZRC20GasLimit(ctx, gas, big.NewInt(42)) - assert.NoError(t, err) + require.NoError(t, err) gasLimit, err := k.GetRevertGasLimit(ctx, types.CrossChainTx{ InboundTxParams: &types.InboundTxParams{ CoinType: common.CoinType_Gas, SenderChainId: chainID, }}) - assert.NoError(t, err) - assert.Equal(t, uint64(42), gasLimit) + require.NoError(t, err) + require.Equal(t, uint64(42), gasLimit) }) t.Run("should return the gas limit of the associated asset", func(t *testing.T) { @@ -199,7 +199,7 @@ func TestGetRevertGasLimit(t *testing.T) { ) _, err := zk.FungibleKeeper.UpdateZRC20GasLimit(ctx, zrc20Addr, big.NewInt(42)) - assert.NoError(t, err) + require.NoError(t, err) gasLimit, err := k.GetRevertGasLimit(ctx, types.CrossChainTx{ InboundTxParams: &types.InboundTxParams{ @@ -207,8 +207,8 @@ func TestGetRevertGasLimit(t *testing.T) { SenderChainId: chainID, Asset: asset, }}) - assert.NoError(t, err) - assert.Equal(t, uint64(42), gasLimit) + require.NoError(t, err) + require.Equal(t, uint64(42), gasLimit) }) t.Run("should fail if no gas coin found", func(t *testing.T) { @@ -219,7 +219,7 @@ func TestGetRevertGasLimit(t *testing.T) { CoinType: common.CoinType_Gas, SenderChainId: 999999, }}) - assert.ErrorIs(t, err, types.ErrForeignCoinNotFound) + require.ErrorIs(t, err, types.ErrForeignCoinNotFound) }) t.Run("should fail if query gas limit for gas coin fails", func(t *testing.T) { @@ -240,7 +240,7 @@ func TestGetRevertGasLimit(t *testing.T) { CoinType: common.CoinType_Gas, SenderChainId: chainID, }}) - assert.ErrorIs(t, err, fungibletypes.ErrContractCall) + require.ErrorIs(t, err, fungibletypes.ErrContractCall) }) t.Run("should fail if no asset found", func(t *testing.T) { @@ -251,7 +251,7 @@ func TestGetRevertGasLimit(t *testing.T) { CoinType: common.CoinType_ERC20, SenderChainId: 999999, }}) - assert.ErrorIs(t, err, types.ErrForeignCoinNotFound) + require.ErrorIs(t, err, types.ErrForeignCoinNotFound) }) t.Run("should fail if query gas limit for asset fails", func(t *testing.T) { @@ -275,6 +275,6 @@ func TestGetRevertGasLimit(t *testing.T) { SenderChainId: chainID, Asset: asset, }}) - assert.ErrorIs(t, err, fungibletypes.ErrContractCall) + require.ErrorIs(t, err, fungibletypes.ErrContractCall) }) } diff --git a/x/crosschain/keeper/evm_deposit_test.go b/x/crosschain/keeper/evm_deposit_test.go index 08287b7047..65483d89c1 100644 --- a/x/crosschain/keeper/evm_deposit_test.go +++ b/x/crosschain/keeper/evm_deposit_test.go @@ -8,8 +8,8 @@ import ( "cosmossdk.io/math" evmtypes "github.com/evmos/ethermint/x/evm/types" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -41,8 +41,8 @@ func TestMsgServer_HandleEVMDeposit(t *testing.T) { }, nil, ) - assert.NoError(t, err) - assert.False(t, reverted) + require.NoError(t, err) + require.False(t, reverted) fungibleMock.AssertExpectations(t) }) @@ -70,8 +70,8 @@ func TestMsgServer_HandleEVMDeposit(t *testing.T) { }, nil, ) - assert.ErrorIs(t, err, errDeposit) - assert.False(t, reverted) + require.ErrorIs(t, err, errDeposit) + require.False(t, reverted) fungibleMock.AssertExpectations(t) }) @@ -114,8 +114,8 @@ func TestMsgServer_HandleEVMDeposit(t *testing.T) { }, senderChain, ) - assert.NoError(t, err) - assert.False(t, reverted) + require.NoError(t, err) + require.False(t, reverted) fungibleMock.AssertExpectations(t) }) @@ -159,8 +159,8 @@ func TestMsgServer_HandleEVMDeposit(t *testing.T) { }, senderChain, ) - assert.ErrorIs(t, err, errDeposit) - assert.False(t, reverted) + require.ErrorIs(t, err, errDeposit) + require.False(t, reverted) fungibleMock.AssertExpectations(t) }) @@ -204,8 +204,8 @@ func TestMsgServer_HandleEVMDeposit(t *testing.T) { }, senderChain, ) - assert.ErrorIs(t, err, errDeposit) - assert.True(t, reverted) + require.ErrorIs(t, err, errDeposit) + require.True(t, reverted) fungibleMock.AssertExpectations(t) }) @@ -248,8 +248,8 @@ func TestMsgServer_HandleEVMDeposit(t *testing.T) { }, senderChain, ) - assert.ErrorIs(t, err, fungibletypes.ErrForeignCoinCapReached) - assert.True(t, reverted) + require.ErrorIs(t, err, fungibletypes.ErrForeignCoinCapReached) + require.True(t, reverted) fungibleMock.AssertExpectations(t) }) @@ -292,8 +292,8 @@ func TestMsgServer_HandleEVMDeposit(t *testing.T) { }, senderChain, ) - assert.ErrorIs(t, err, fungibletypes.ErrPausedZRC20) - assert.True(t, reverted) + require.ErrorIs(t, err, fungibletypes.ErrPausedZRC20) + require.True(t, reverted) fungibleMock.AssertExpectations(t) }) @@ -334,8 +334,8 @@ func TestMsgServer_HandleEVMDeposit(t *testing.T) { }, senderChain, ) - assert.ErrorIs(t, err, fungibletypes.ErrCallNonContract) - assert.True(t, reverted) + require.ErrorIs(t, err, fungibletypes.ErrCallNonContract) + require.True(t, reverted) fungibleMock.AssertExpectations(t) }) @@ -358,7 +358,7 @@ func TestMsgServer_HandleEVMDeposit(t *testing.T) { }, senderChain, ) - assert.ErrorIs(t, err, types.ErrUnableToParseAddress) + require.ErrorIs(t, err, types.ErrUnableToParseAddress) }) t.Run("should deposit into address if address is parsed", func(t *testing.T) { @@ -373,7 +373,7 @@ func TestMsgServer_HandleEVMDeposit(t *testing.T) { amount := big.NewInt(42) data, err := hex.DecodeString("DEADBEEF") - assert.NoError(t, err) + require.NoError(t, err) fungibleMock.On( "ZRC20DepositAndCallContract", ctx, @@ -399,8 +399,8 @@ func TestMsgServer_HandleEVMDeposit(t *testing.T) { }, senderChain, ) - assert.NoError(t, err) - assert.False(t, reverted) + require.NoError(t, err) + require.False(t, reverted) fungibleMock.AssertExpectations(t) }) @@ -416,7 +416,7 @@ func TestMsgServer_HandleEVMDeposit(t *testing.T) { amount := big.NewInt(42) data, err := hex.DecodeString("DEADBEEF") - assert.NoError(t, err) + require.NoError(t, err) fungibleMock.On( "ZRC20DepositAndCallContract", ctx, @@ -442,8 +442,8 @@ func TestMsgServer_HandleEVMDeposit(t *testing.T) { }, senderChain, ) - assert.NoError(t, err) - assert.False(t, reverted) + require.NoError(t, err) + require.False(t, reverted) fungibleMock.AssertExpectations(t) }) diff --git a/x/crosschain/keeper/finalized_inbounds_test.go b/x/crosschain/keeper/finalized_inbounds_test.go index 29cdf83b0e..9946024aa8 100644 --- a/x/crosschain/keeper/finalized_inbounds_test.go +++ b/x/crosschain/keeper/finalized_inbounds_test.go @@ -3,7 +3,7 @@ package keeper_test import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/crosschain/types" @@ -16,14 +16,14 @@ func TestKeeper_IsFinalizedInbound(t *testing.T) { chainID := sample.Chain(5).ChainId eventIndex := sample.EventIndex() k.AddFinalizedInbound(ctx, intxHash, chainID, eventIndex) - assert.True(t, k.IsFinalizedInbound(ctx, intxHash, chainID, eventIndex)) + require.True(t, k.IsFinalizedInbound(ctx, intxHash, chainID, eventIndex)) }) t.Run("check false for non-finalized inbound", func(t *testing.T) { k, ctx, _, _ := keepertest.CrosschainKeeper(t) intxHash := sample.Hash().String() chainID := sample.Chain(5).ChainId eventIndex := sample.EventIndex() - assert.False(t, k.IsFinalizedInbound(ctx, intxHash, chainID, eventIndex)) + require.False(t, k.IsFinalizedInbound(ctx, intxHash, chainID, eventIndex)) }) t.Run("check true for finalized inbound list", func(t *testing.T) { k, ctx, _, _ := keepertest.CrosschainKeeper(t) @@ -38,7 +38,7 @@ func TestKeeper_IsFinalizedInbound(t *testing.T) { k.AddFinalizedInbound(ctx, txHashList[i], chainIdList[i], eventIndexList[i]) } for i := 0; i < listSize; i++ { - assert.True(t, k.IsFinalizedInbound(ctx, txHashList[i], chainIdList[i], eventIndexList[i])) + require.True(t, k.IsFinalizedInbound(ctx, txHashList[i], chainIdList[i], eventIndexList[i])) } }) } @@ -50,7 +50,7 @@ func TestKeeper_AddFinalizedInbound(t *testing.T) { chainID := sample.Chain(5).ChainId eventIndex := sample.EventIndex() k.AddFinalizedInbound(ctx, intxHash, chainID, eventIndex) - assert.True(t, k.IsFinalizedInbound(ctx, intxHash, chainID, eventIndex)) + require.True(t, k.IsFinalizedInbound(ctx, intxHash, chainID, eventIndex)) }) } @@ -58,7 +58,7 @@ func TestKeeper_GetAllFinalizedInbound(t *testing.T) { t.Run("check empty list", func(t *testing.T) { k, ctx, _, _ := keepertest.CrosschainKeeper(t) list := k.GetAllFinalizedInbound(ctx) - assert.Empty(t, list) + require.Empty(t, list) }) t.Run("check list", func(t *testing.T) { k, ctx, _, _ := keepertest.CrosschainKeeper(t) @@ -73,10 +73,10 @@ func TestKeeper_GetAllFinalizedInbound(t *testing.T) { k.AddFinalizedInbound(ctx, txHashList[i], chainIdList[i], eventIndexList[i]) } list := k.GetAllFinalizedInbound(ctx) - assert.Equal(t, listSize, len(list)) + require.Equal(t, listSize, len(list)) for i := 0; i < listSize; i++ { - assert.Contains(t, list, types.FinalizedInboundKey(txHashList[i], chainIdList[i], eventIndexList[i])) + require.Contains(t, list, types.FinalizedInboundKey(txHashList[i], chainIdList[i], eventIndexList[i])) } - assert.NotContains(t, list, types.FinalizedInboundKey(sample.Hash().String(), sample.Chain(5).ChainId, sample.EventIndex())) + require.NotContains(t, list, types.FinalizedInboundKey(sample.Hash().String(), sample.Chain(5).ChainId, sample.EventIndex())) }) } diff --git a/x/crosschain/keeper/gas_payment_test.go b/x/crosschain/keeper/gas_payment_test.go index b15b2065af..d0a702daf5 100644 --- a/x/crosschain/keeper/gas_payment_test.go +++ b/x/crosschain/keeper/gas_payment_test.go @@ -7,7 +7,7 @@ import ( "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" zetacommon "github.com/zeta-chain/zetacore/common" testkeeper "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -42,7 +42,7 @@ func TestKeeper_PayGasNativeAndUpdateCctx(t *testing.T) { sdk.UnwrapSDKContext(ctx), fungibletypes.NewMsgUpdateZRC20WithdrawFee(admin, zrc20.String(), sdk.NewUint(withdrawFee), math.Uint{}), ) - assert.NoError(t, err) + require.NoError(t, err) k.SetGasPrice(ctx, types.GasPrice{ ChainId: chainID, MedianIndex: 0, @@ -67,10 +67,10 @@ func TestKeeper_PayGasNativeAndUpdateCctx(t *testing.T) { // total fees must be 21000*2+1000=43000 // if the input amount of the cctx is 1e16, the output amount must be 1e16-43000=9999999999957000 err = k.PayGasNativeAndUpdateCctx(ctx, chainID, &cctx, math.NewUint(inputAmount)) - assert.NoError(t, err) - assert.Equal(t, uint64(9999999999957000), cctx.GetCurrentOutTxParam().Amount.Uint64()) - assert.Equal(t, uint64(21_000), cctx.GetCurrentOutTxParam().OutboundTxGasLimit) - assert.Equal(t, "2", cctx.GetCurrentOutTxParam().OutboundTxGasPrice) + require.NoError(t, err) + require.Equal(t, uint64(9999999999957000), cctx.GetCurrentOutTxParam().Amount.Uint64()) + require.Equal(t, uint64(21_000), cctx.GetCurrentOutTxParam().OutboundTxGasLimit) + require.Equal(t, "2", cctx.GetCurrentOutTxParam().OutboundTxGasPrice) }) t.Run("should fail if not coin type gas", func(t *testing.T) { @@ -82,7 +82,7 @@ func TestKeeper_PayGasNativeAndUpdateCctx(t *testing.T) { }, } err := k.PayGasNativeAndUpdateCctx(ctx, chainID, &cctx, math.NewUint(inputAmount)) - assert.ErrorIs(t, err, types.ErrInvalidCoinType) + require.ErrorIs(t, err, types.ErrInvalidCoinType) }) t.Run("should fail if chain is not supported", func(t *testing.T) { @@ -93,7 +93,7 @@ func TestKeeper_PayGasNativeAndUpdateCctx(t *testing.T) { }, } err := k.PayGasNativeAndUpdateCctx(ctx, 999999, &cctx, math.NewUint(inputAmount)) - assert.ErrorIs(t, err, observertypes.ErrSupportedChains) + require.ErrorIs(t, err, observertypes.ErrSupportedChains) }) t.Run("should fail if can't query the gas price", func(t *testing.T) { @@ -124,7 +124,7 @@ func TestKeeper_PayGasNativeAndUpdateCctx(t *testing.T) { } err := k.PayGasNativeAndUpdateCctx(ctx, chainID, &cctx, math.NewUint(inputAmount)) - assert.ErrorIs(t, err, types.ErrCannotFindGasParams) + require.ErrorIs(t, err, types.ErrCannotFindGasParams) }) t.Run("should fail if not enough amount for the fee", func(t *testing.T) { @@ -143,7 +143,7 @@ func TestKeeper_PayGasNativeAndUpdateCctx(t *testing.T) { sdk.UnwrapSDKContext(ctx), fungibletypes.NewMsgUpdateZRC20WithdrawFee(admin, zrc20.String(), sdk.NewUint(withdrawFee), math.Uint{}), ) - assert.NoError(t, err) + require.NoError(t, err) k.SetGasPrice(ctx, types.GasPrice{ ChainId: chainID, MedianIndex: 0, @@ -166,7 +166,7 @@ func TestKeeper_PayGasNativeAndUpdateCctx(t *testing.T) { // 42999 < 43000 err = k.PayGasNativeAndUpdateCctx(ctx, chainID, &cctx, math.NewUint(42999)) - assert.ErrorIs(t, err, types.ErrNotEnoughGas) + require.ErrorIs(t, err, types.ErrNotEnoughGas) }) } @@ -199,7 +199,7 @@ func TestKeeper_PayGasInERC20AndUpdateCctx(t *testing.T) { sdk.UnwrapSDKContext(ctx), fungibletypes.NewMsgUpdateZRC20WithdrawFee(admin, gasZRC20.String(), sdk.NewUint(withdrawFee), math.Uint{}), ) - assert.NoError(t, err) + require.NoError(t, err) k.SetGasPrice(ctx, types.GasPrice{ ChainId: chainID, MedianIndex: 0, @@ -233,15 +233,15 @@ func TestKeeper_PayGasInERC20AndUpdateCctx(t *testing.T) { // total fees in gas must be 21000*2+1000=43000 // we calculate what it represents in erc20 expectedInZeta, err := zk.FungibleKeeper.QueryUniswapV2RouterGetZetaAmountsIn(ctx, big.NewInt(43000), gasZRC20) - assert.NoError(t, err) + require.NoError(t, err) expectedInZRC20, err := zk.FungibleKeeper.QueryUniswapV2RouterGetZRC4AmountsIn(ctx, expectedInZeta, zrc20Addr) - assert.NoError(t, err) + require.NoError(t, err) err = k.PayGasInERC20AndUpdateCctx(ctx, chainID, &cctx, math.NewUint(inputAmount), false) - assert.NoError(t, err) - assert.Equal(t, inputAmount-expectedInZRC20.Uint64(), cctx.GetCurrentOutTxParam().Amount.Uint64()) - assert.Equal(t, uint64(21_000), cctx.GetCurrentOutTxParam().OutboundTxGasLimit) - assert.Equal(t, "2", cctx.GetCurrentOutTxParam().OutboundTxGasPrice) + require.NoError(t, err) + require.Equal(t, inputAmount-expectedInZRC20.Uint64(), cctx.GetCurrentOutTxParam().Amount.Uint64()) + require.Equal(t, uint64(21_000), cctx.GetCurrentOutTxParam().OutboundTxGasLimit) + require.Equal(t, "2", cctx.GetCurrentOutTxParam().OutboundTxGasPrice) }) t.Run("should fail if not coin type erc20", func(t *testing.T) { @@ -253,7 +253,7 @@ func TestKeeper_PayGasInERC20AndUpdateCctx(t *testing.T) { }, } err := k.PayGasInERC20AndUpdateCctx(ctx, chainID, &cctx, math.NewUint(inputAmount), false) - assert.ErrorIs(t, err, types.ErrInvalidCoinType) + require.ErrorIs(t, err, types.ErrInvalidCoinType) }) t.Run("should fail if chain is not supported", func(t *testing.T) { @@ -264,7 +264,7 @@ func TestKeeper_PayGasInERC20AndUpdateCctx(t *testing.T) { }, } err := k.PayGasInERC20AndUpdateCctx(ctx, 999999, &cctx, math.NewUint(inputAmount), false) - assert.ErrorIs(t, err, observertypes.ErrSupportedChains) + require.ErrorIs(t, err, observertypes.ErrSupportedChains) }) t.Run("should fail if can't query the gas price", func(t *testing.T) { @@ -295,7 +295,7 @@ func TestKeeper_PayGasInERC20AndUpdateCctx(t *testing.T) { } err := k.PayGasInERC20AndUpdateCctx(ctx, chainID, &cctx, math.NewUint(inputAmount), false) - assert.ErrorIs(t, err, types.ErrCannotFindGasParams) + require.ErrorIs(t, err, types.ErrCannotFindGasParams) }) t.Run("should fail if can't find the ZRC20", func(t *testing.T) { @@ -315,7 +315,7 @@ func TestKeeper_PayGasInERC20AndUpdateCctx(t *testing.T) { sdk.UnwrapSDKContext(ctx), fungibletypes.NewMsgUpdateZRC20WithdrawFee(admin, gasZRC20.String(), sdk.NewUint(withdrawFee), math.Uint{}), ) - assert.NoError(t, err) + require.NoError(t, err) k.SetGasPrice(ctx, types.GasPrice{ ChainId: chainID, MedianIndex: 0, @@ -341,7 +341,7 @@ func TestKeeper_PayGasInERC20AndUpdateCctx(t *testing.T) { } err = k.PayGasInERC20AndUpdateCctx(ctx, chainID, &cctx, math.NewUint(inputAmount), false) - assert.ErrorIs(t, err, types.ErrForeignCoinNotFound) + require.ErrorIs(t, err, types.ErrForeignCoinNotFound) }) t.Run("should fail if liquidity pool not setup", func(t *testing.T) { @@ -371,7 +371,7 @@ func TestKeeper_PayGasInERC20AndUpdateCctx(t *testing.T) { sdk.UnwrapSDKContext(ctx), fungibletypes.NewMsgUpdateZRC20WithdrawFee(admin, gasZRC20.String(), sdk.NewUint(withdrawFee), math.Uint{}), ) - assert.NoError(t, err) + require.NoError(t, err) k.SetGasPrice(ctx, types.GasPrice{ ChainId: chainID, MedianIndex: 0, @@ -397,7 +397,7 @@ func TestKeeper_PayGasInERC20AndUpdateCctx(t *testing.T) { } err = k.PayGasInERC20AndUpdateCctx(ctx, chainID, &cctx, math.NewUint(inputAmount), false) - assert.ErrorIs(t, err, types.ErrNoLiquidityPool) + require.ErrorIs(t, err, types.ErrNoLiquidityPool) }) t.Run("should fail if not enough amount for the fee", func(t *testing.T) { @@ -427,7 +427,7 @@ func TestKeeper_PayGasInERC20AndUpdateCctx(t *testing.T) { sdk.UnwrapSDKContext(ctx), fungibletypes.NewMsgUpdateZRC20WithdrawFee(admin, gasZRC20.String(), sdk.NewUint(withdrawFee), math.Uint{}), ) - assert.NoError(t, err) + require.NoError(t, err) k.SetGasPrice(ctx, types.GasPrice{ ChainId: chainID, MedianIndex: 0, @@ -461,13 +461,13 @@ func TestKeeper_PayGasInERC20AndUpdateCctx(t *testing.T) { // total fees in gas must be 21000*2+1000=43000 // we calculate what it represents in erc20 expectedInZeta, err := zk.FungibleKeeper.QueryUniswapV2RouterGetZetaAmountsIn(ctx, big.NewInt(43000), gasZRC20) - assert.NoError(t, err) + require.NoError(t, err) expectedInZRC20, err := zk.FungibleKeeper.QueryUniswapV2RouterGetZRC4AmountsIn(ctx, expectedInZeta, zrc20Addr) - assert.NoError(t, err) + require.NoError(t, err) // Provide expected value minus 1 err = k.PayGasInERC20AndUpdateCctx(ctx, chainID, &cctx, math.NewUintFromBigInt(expectedInZRC20).SubUint64(1), false) - assert.ErrorIs(t, err, types.ErrNotEnoughGas) + require.ErrorIs(t, err, types.ErrNotEnoughGas) }) } @@ -504,16 +504,16 @@ func TestKeeper_PayGasInZetaAndUpdateCctx(t *testing.T) { } // gasLimit * gasPrice * 2 = 1000 * 2 * 2 = 4000 expectedOutTxGasFeeInZeta, err := zk.FungibleKeeper.QueryUniswapV2RouterGetZetaAmountsIn(ctx, big.NewInt(4000), zrc20) - assert.NoError(t, err) + require.NoError(t, err) // the output amount must be input amount - (out tx fee in zeta + protocol flat fee) expectedFeeInZeta := types.GetProtocolFee().Add(math.NewUintFromBigInt(expectedOutTxGasFeeInZeta)) inputAmount := expectedFeeInZeta.Add(math.NewUint(100000)) err = k.PayGasInZetaAndUpdateCctx(ctx, chainID, &cctx, inputAmount, false) - assert.NoError(t, err) - assert.Equal(t, "100000", cctx.GetCurrentOutTxParam().Amount.String()) - assert.Equal(t, "4", cctx.GetCurrentOutTxParam().OutboundTxGasPrice) // gas price is doubled - assert.True(t, cctx.ZetaFees.Equal(expectedFeeInZeta.Add(math.NewUint(100))), "expected %s, got %s", expectedFeeInZeta.String(), cctx.ZetaFees.String()) + require.NoError(t, err) + require.Equal(t, "100000", cctx.GetCurrentOutTxParam().Amount.String()) + require.Equal(t, "4", cctx.GetCurrentOutTxParam().OutboundTxGasPrice) // gas price is doubled + require.True(t, cctx.ZetaFees.Equal(expectedFeeInZeta.Add(math.NewUint(100))), "expected %s, got %s", expectedFeeInZeta.String(), cctx.ZetaFees.String()) // can call with undefined zeta fees cctx = types.CrossChainTx{ @@ -528,14 +528,14 @@ func TestKeeper_PayGasInZetaAndUpdateCctx(t *testing.T) { }, } expectedOutTxGasFeeInZeta, err = zk.FungibleKeeper.QueryUniswapV2RouterGetZetaAmountsIn(ctx, big.NewInt(4000), zrc20) - assert.NoError(t, err) + require.NoError(t, err) expectedFeeInZeta = types.GetProtocolFee().Add(math.NewUintFromBigInt(expectedOutTxGasFeeInZeta)) inputAmount = expectedFeeInZeta.Add(math.NewUint(100000)) err = k.PayGasInZetaAndUpdateCctx(ctx, chainID, &cctx, inputAmount, false) - assert.NoError(t, err) - assert.Equal(t, "100000", cctx.GetCurrentOutTxParam().Amount.String()) - assert.Equal(t, "4", cctx.GetCurrentOutTxParam().OutboundTxGasPrice) // gas price is doubled - assert.True(t, cctx.ZetaFees.Equal(expectedFeeInZeta), "expected %s, got %s", expectedFeeInZeta.String(), cctx.ZetaFees.String()) + require.NoError(t, err) + require.Equal(t, "100000", cctx.GetCurrentOutTxParam().Amount.String()) + require.Equal(t, "4", cctx.GetCurrentOutTxParam().OutboundTxGasPrice) // gas price is doubled + require.True(t, cctx.ZetaFees.Equal(expectedFeeInZeta), "expected %s, got %s", expectedFeeInZeta.String(), cctx.ZetaFees.String()) }) t.Run("should fail if pay gas in zeta with coin type other than zeta", func(t *testing.T) { @@ -547,7 +547,7 @@ func TestKeeper_PayGasInZetaAndUpdateCctx(t *testing.T) { }, } err := k.PayGasInZetaAndUpdateCctx(ctx, chainID, &cctx, math.NewUint(100000), false) - assert.ErrorIs(t, err, types.ErrInvalidCoinType) + require.ErrorIs(t, err, types.ErrInvalidCoinType) }) t.Run("should fail if chain is not supported", func(t *testing.T) { @@ -558,7 +558,7 @@ func TestKeeper_PayGasInZetaAndUpdateCctx(t *testing.T) { }, } err := k.PayGasInZetaAndUpdateCctx(ctx, 999999, &cctx, math.NewUint(100000), false) - assert.ErrorIs(t, err, observertypes.ErrSupportedChains) + require.ErrorIs(t, err, observertypes.ErrSupportedChains) }) t.Run("should fail if can't query the gas price", func(t *testing.T) { @@ -589,7 +589,7 @@ func TestKeeper_PayGasInZetaAndUpdateCctx(t *testing.T) { } err := k.PayGasInZetaAndUpdateCctx(ctx, chainID, &cctx, math.NewUint(100000), false) - assert.ErrorIs(t, err, types.ErrUnableToGetGasPrice) + require.ErrorIs(t, err, types.ErrUnableToGetGasPrice) }) t.Run("should fail if not enough amount for the fee", func(t *testing.T) { @@ -623,12 +623,12 @@ func TestKeeper_PayGasInZetaAndUpdateCctx(t *testing.T) { ZetaFees: math.NewUint(100), } expectedOutTxGasFeeInZeta, err := zk.FungibleKeeper.QueryUniswapV2RouterGetZetaAmountsIn(ctx, big.NewInt(4000), zrc20) - assert.NoError(t, err) + require.NoError(t, err) expectedFeeInZeta := types.GetProtocolFee().Add(math.NewUintFromBigInt(expectedOutTxGasFeeInZeta)) // set input amount lower than total zeta fee inputAmount := expectedFeeInZeta.Sub(math.NewUint(1)) err = k.PayGasInZetaAndUpdateCctx(ctx, chainID, &cctx, inputAmount, false) - assert.ErrorIs(t, err, types.ErrNotEnoughZetaBurnt) + require.ErrorIs(t, err, types.ErrNotEnoughZetaBurnt) }) } diff --git a/x/crosschain/keeper/gas_price_test.go b/x/crosschain/keeper/gas_price_test.go index 9a269832c2..67aeb95cd6 100644 --- a/x/crosschain/keeper/gas_price_test.go +++ b/x/crosschain/keeper/gas_price_test.go @@ -5,7 +5,7 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/x/crosschain/types" ) @@ -26,8 +26,8 @@ func TestGasPriceGet(t *testing.T) { items := createNGasPrice(keeper, ctx, 10) for _, item := range items { rst, found := keeper.GetGasPrice(ctx, item.ChainId) - assert.True(t, found) - assert.Equal(t, item, rst) + require.True(t, found) + require.Equal(t, item, rst) } } func TestGasPriceRemove(t *testing.T) { @@ -36,12 +36,12 @@ func TestGasPriceRemove(t *testing.T) { for _, item := range items { keeper.RemoveGasPrice(ctx, item.Index) _, found := keeper.GetGasPrice(ctx, item.ChainId) - assert.False(t, found) + require.False(t, found) } } func TestGasPriceGetAll(t *testing.T) { keeper, ctx := setupKeeper(t) items := createNGasPrice(keeper, ctx, 10) - assert.Equal(t, items, keeper.GetAllGasPrice(ctx)) + require.Equal(t, items, keeper.GetAllGasPrice(ctx)) } diff --git a/x/crosschain/keeper/grpc_query_cctx_test.go b/x/crosschain/keeper/grpc_query_cctx_test.go index 5c632a6a10..c326f41a42 100644 --- a/x/crosschain/keeper/grpc_query_cctx_test.go +++ b/x/crosschain/keeper/grpc_query_cctx_test.go @@ -5,7 +5,7 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/crosschain/keeper" @@ -68,19 +68,19 @@ func TestKeeper_CctxListPending(t *testing.T) { t.Run("should fail for empty req", func(t *testing.T) { k, ctx, _, _ := keepertest.CrosschainKeeper(t) _, err := k.CctxListPending(ctx, nil) - assert.ErrorContains(t, err, "invalid request") + require.ErrorContains(t, err, "invalid request") }) t.Run("should fail if limit is too high", func(t *testing.T) { k, ctx, _, _ := keepertest.CrosschainKeeper(t) _, err := k.CctxListPending(ctx, &types.QueryListCctxPendingRequest{Limit: keeper.MaxPendingCctxs + 1}) - assert.ErrorContains(t, err, "limit exceeds max limit of") + require.ErrorContains(t, err, "limit exceeds max limit of") }) t.Run("should fail if no TSS", func(t *testing.T) { k, ctx, _, _ := keepertest.CrosschainKeeper(t) _, err := k.CctxListPending(ctx, &types.QueryListCctxPendingRequest{Limit: 1}) - assert.ErrorContains(t, err, "tss not found") + require.ErrorContains(t, err, "tss not found") }) t.Run("should return empty list if no nonces", func(t *testing.T) { @@ -90,7 +90,7 @@ func TestKeeper_CctxListPending(t *testing.T) { zk.ObserverKeeper.SetTSS(ctx, sample.Tss()) _, err := k.CctxListPending(ctx, &types.QueryListCctxPendingRequest{Limit: 1}) - assert.ErrorContains(t, err, "pending nonces not found") + require.ErrorContains(t, err, "pending nonces not found") }) t.Run("can retrieve pending cctx in range", func(t *testing.T) { @@ -101,16 +101,16 @@ func TestKeeper_CctxListPending(t *testing.T) { cctxs := createCctxWithNonceRange(t, ctx, *k, 1000, 2000, chainID, tss, zk) res, err := k.CctxListPending(ctx, &types.QueryListCctxPendingRequest{ChainId: chainID, Limit: 100}) - assert.NoError(t, err) - assert.Equal(t, 100, len(res.CrossChainTx)) - assert.EqualValues(t, cctxs[0:100], res.CrossChainTx) - assert.EqualValues(t, uint64(1000), res.TotalPending) + require.NoError(t, err) + require.Equal(t, 100, len(res.CrossChainTx)) + require.EqualValues(t, cctxs[0:100], res.CrossChainTx) + require.EqualValues(t, uint64(1000), res.TotalPending) res, err = k.CctxListPending(ctx, &types.QueryListCctxPendingRequest{ChainId: chainID}) - assert.NoError(t, err) - assert.Equal(t, keeper.MaxPendingCctxs, len(res.CrossChainTx)) - assert.EqualValues(t, cctxs[0:keeper.MaxPendingCctxs], res.CrossChainTx) - assert.EqualValues(t, uint64(1000), res.TotalPending) + require.NoError(t, err) + require.Equal(t, keeper.MaxPendingCctxs, len(res.CrossChainTx)) + require.EqualValues(t, cctxs[0:keeper.MaxPendingCctxs], res.CrossChainTx) + require.EqualValues(t, uint64(1000), res.TotalPending) }) t.Run("can retrieve pending cctx with range smaller than max", func(t *testing.T) { @@ -121,10 +121,10 @@ func TestKeeper_CctxListPending(t *testing.T) { cctxs := createCctxWithNonceRange(t, ctx, *k, 1000, 1100, chainID, tss, zk) res, err := k.CctxListPending(ctx, &types.QueryListCctxPendingRequest{ChainId: chainID}) - assert.NoError(t, err) - assert.Equal(t, 100, len(res.CrossChainTx)) - assert.EqualValues(t, cctxs, res.CrossChainTx) - assert.EqualValues(t, uint64(100), res.TotalPending) + require.NoError(t, err) + require.Equal(t, 100, len(res.CrossChainTx)) + require.EqualValues(t, cctxs, res.CrossChainTx) + require.EqualValues(t, uint64(100), res.TotalPending) }) t.Run("can retrieve pending cctx with pending cctx below nonce low", func(t *testing.T) { @@ -136,23 +136,23 @@ func TestKeeper_CctxListPending(t *testing.T) { // set some cctxs as pending below nonce cctx1, found := k.GetCrossChainTx(ctx, "1337-940") - assert.True(t, found) + require.True(t, found) cctx1.CctxStatus.Status = types.CctxStatus_PendingOutbound k.SetCrossChainTx(ctx, cctx1) cctx2, found := k.GetCrossChainTx(ctx, "1337-955") - assert.True(t, found) + require.True(t, found) cctx2.CctxStatus.Status = types.CctxStatus_PendingOutbound k.SetCrossChainTx(ctx, cctx2) res, err := k.CctxListPending(ctx, &types.QueryListCctxPendingRequest{ChainId: chainID, Limit: 100}) - assert.NoError(t, err) - assert.Equal(t, 100, len(res.CrossChainTx)) + require.NoError(t, err) + require.Equal(t, 100, len(res.CrossChainTx)) expectedCctxs := append([]*types.CrossChainTx{&cctx1, &cctx2}, cctxs[0:98]...) - assert.EqualValues(t, expectedCctxs, res.CrossChainTx) + require.EqualValues(t, expectedCctxs, res.CrossChainTx) // pending nonce + 2 - assert.EqualValues(t, uint64(1002), res.TotalPending) + require.EqualValues(t, uint64(1002), res.TotalPending) }) } diff --git a/x/crosschain/keeper/grpc_query_gas_price_test.go b/x/crosschain/keeper/grpc_query_gas_price_test.go index 7b4a88cf0c..cc48e2f3b0 100644 --- a/x/crosschain/keeper/grpc_query_gas_price_test.go +++ b/x/crosschain/keeper/grpc_query_gas_price_test.go @@ -5,7 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/x/crosschain/types" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -45,9 +45,9 @@ func TestGasPriceQuerySingle(t *testing.T) { t.Run(tc.desc, func(t *testing.T) { response, err := keeper.GasPrice(wctx, tc.request) if tc.err != nil { - assert.ErrorIs(t, err, tc.err) + require.ErrorIs(t, err, tc.err) } else { - assert.Equal(t, tc.response, response) + require.Equal(t, tc.response, response) } }) } @@ -72,9 +72,9 @@ func TestGasPriceQueryPaginated(t *testing.T) { step := 2 for i := 0; i < len(msgs); i += step { resp, err := keeper.GasPriceAll(wctx, request(nil, uint64(i), uint64(step), false)) - assert.NoError(t, err) + require.NoError(t, err) for j := i; j < len(msgs) && j < i+step; j++ { - assert.Equal(t, &msgs[j], resp.GasPrice[j-i]) + require.Equal(t, &msgs[j], resp.GasPrice[j-i]) } } }) @@ -83,20 +83,20 @@ func TestGasPriceQueryPaginated(t *testing.T) { var next []byte for i := 0; i < len(msgs); i += step { resp, err := keeper.GasPriceAll(wctx, request(next, 0, uint64(step), false)) - assert.NoError(t, err) + require.NoError(t, err) for j := i; j < len(msgs) && j < i+step; j++ { - assert.Equal(t, &msgs[j], resp.GasPrice[j-i]) + require.Equal(t, &msgs[j], resp.GasPrice[j-i]) } next = resp.Pagination.NextKey } }) t.Run("Total", func(t *testing.T) { resp, err := keeper.GasPriceAll(wctx, request(nil, 0, 0, true)) - assert.NoError(t, err) - assert.Equal(t, len(msgs), int(resp.Pagination.Total)) + require.NoError(t, err) + require.Equal(t, len(msgs), int(resp.Pagination.Total)) }) t.Run("InvalidRequest", func(t *testing.T) { _, err := keeper.GasPriceAll(wctx, nil) - assert.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) + require.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) }) } diff --git a/x/crosschain/keeper/grpc_query_in_tx_hash_to_cctx_test.go b/x/crosschain/keeper/grpc_query_in_tx_hash_to_cctx_test.go index 6d00f1b562..5704fdc54a 100644 --- a/x/crosschain/keeper/grpc_query_in_tx_hash_to_cctx_test.go +++ b/x/crosschain/keeper/grpc_query_in_tx_hash_to_cctx_test.go @@ -9,7 +9,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -58,10 +58,10 @@ func TestInTxHashToCctxQuerySingle(t *testing.T) { t.Run(tc.desc, func(t *testing.T) { response, err := keeper.InTxHashToCctx(wctx, tc.request) if tc.err != nil { - assert.ErrorIs(t, err, tc.err) + require.ErrorIs(t, err, tc.err) } else { - assert.NoError(t, err) - assert.Equal(t, + require.NoError(t, err) + require.Equal(t, nullify.Fill(tc.response), nullify.Fill(response), ) @@ -89,9 +89,9 @@ func TestInTxHashToCctxQueryPaginated(t *testing.T) { step := 2 for i := 0; i < len(msgs); i += step { resp, err := keeper.InTxHashToCctxAll(wctx, request(nil, uint64(i), uint64(step), false)) - assert.NoError(t, err) - assert.LessOrEqual(t, len(resp.InTxHashToCctx), step) - assert.Subset(t, + require.NoError(t, err) + require.LessOrEqual(t, len(resp.InTxHashToCctx), step) + require.Subset(t, nullify.Fill(msgs), nullify.Fill(resp.InTxHashToCctx), ) @@ -102,9 +102,9 @@ func TestInTxHashToCctxQueryPaginated(t *testing.T) { var next []byte for i := 0; i < len(msgs); i += step { resp, err := keeper.InTxHashToCctxAll(wctx, request(next, 0, uint64(step), false)) - assert.NoError(t, err) - assert.LessOrEqual(t, len(resp.InTxHashToCctx), step) - assert.Subset(t, + require.NoError(t, err) + require.LessOrEqual(t, len(resp.InTxHashToCctx), step) + require.Subset(t, nullify.Fill(msgs), nullify.Fill(resp.InTxHashToCctx), ) @@ -113,16 +113,16 @@ func TestInTxHashToCctxQueryPaginated(t *testing.T) { }) t.Run("Total", func(t *testing.T) { resp, err := keeper.InTxHashToCctxAll(wctx, request(nil, 0, 0, true)) - assert.NoError(t, err) - assert.Equal(t, len(msgs), int(resp.Pagination.Total)) - assert.ElementsMatch(t, + require.NoError(t, err) + require.Equal(t, len(msgs), int(resp.Pagination.Total)) + require.ElementsMatch(t, nullify.Fill(msgs), nullify.Fill(resp.InTxHashToCctx), ) }) t.Run("InvalidRequest", func(t *testing.T) { _, err := keeper.InTxHashToCctxAll(wctx, nil) - assert.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) + require.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) }) } @@ -157,10 +157,10 @@ func TestKeeper_InTxHashToCctxDataQuery(t *testing.T) { InTxHash: inTxHashToCctx.InTxHash, } res, err := keeper.InTxHashToCctxData(wctx, req) - assert.NoError(t, err) - assert.Equal(t, len(cctxs), len(res.CrossChainTxs)) + require.NoError(t, err) + require.Equal(t, len(cctxs), len(res.CrossChainTxs)) for i := range cctxs { - assert.Equal(t, nullify.Fill(cctxs[i]), nullify.Fill(res.CrossChainTxs[i])) + require.Equal(t, nullify.Fill(cctxs[i]), nullify.Fill(res.CrossChainTxs[i])) } }) t.Run("in tx hash not found", func(t *testing.T) { @@ -168,7 +168,7 @@ func TestKeeper_InTxHashToCctxDataQuery(t *testing.T) { InTxHash: "notfound", } _, err := keeper.InTxHashToCctxData(wctx, req) - assert.ErrorIs(t, err, status.Error(codes.NotFound, "not found")) + require.ErrorIs(t, err, status.Error(codes.NotFound, "not found")) }) t.Run("cctx not indexed return internal error", func(t *testing.T) { keeper.SetInTxHashToCctx(ctx, types.InTxHashToCctx{ @@ -180,6 +180,6 @@ func TestKeeper_InTxHashToCctxDataQuery(t *testing.T) { InTxHash: "nocctx", } _, err := keeper.InTxHashToCctxData(wctx, req) - assert.ErrorIs(t, err, status.Error(codes.Internal, "cctx indexed notfound doesn't exist")) + require.ErrorIs(t, err, status.Error(codes.Internal, "cctx indexed notfound doesn't exist")) }) } diff --git a/x/crosschain/keeper/grpc_query_last_block_height_test.go b/x/crosschain/keeper/grpc_query_last_block_height_test.go index 428a246a61..f2747bf7c9 100644 --- a/x/crosschain/keeper/grpc_query_last_block_height_test.go +++ b/x/crosschain/keeper/grpc_query_last_block_height_test.go @@ -5,7 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/x/crosschain/types" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -45,9 +45,9 @@ func TestLastBlockHeightQuerySingle(t *testing.T) { t.Run(tc.desc, func(t *testing.T) { response, err := keeper.LastBlockHeight(wctx, tc.request) if tc.err != nil { - assert.ErrorIs(t, err, tc.err) + require.ErrorIs(t, err, tc.err) } else { - assert.Equal(t, tc.response, response) + require.Equal(t, tc.response, response) } }) } @@ -72,9 +72,9 @@ func TestLastBlockHeightQueryPaginated(t *testing.T) { step := 2 for i := 0; i < len(msgs); i += step { resp, err := keeper.LastBlockHeightAll(wctx, request(nil, uint64(i), uint64(step), false)) - assert.NoError(t, err) + require.NoError(t, err) for j := i; j < len(msgs) && j < i+step; j++ { - assert.Equal(t, &msgs[j], resp.LastBlockHeight[j-i]) + require.Equal(t, &msgs[j], resp.LastBlockHeight[j-i]) } } }) @@ -83,20 +83,20 @@ func TestLastBlockHeightQueryPaginated(t *testing.T) { var next []byte for i := 0; i < len(msgs); i += step { resp, err := keeper.LastBlockHeightAll(wctx, request(next, 0, uint64(step), false)) - assert.NoError(t, err) + require.NoError(t, err) for j := i; j < len(msgs) && j < i+step; j++ { - assert.Equal(t, &msgs[j], resp.LastBlockHeight[j-i]) + require.Equal(t, &msgs[j], resp.LastBlockHeight[j-i]) } next = resp.Pagination.NextKey } }) t.Run("Total", func(t *testing.T) { resp, err := keeper.LastBlockHeightAll(wctx, request(nil, 0, 0, true)) - assert.NoError(t, err) - assert.Equal(t, len(msgs), int(resp.Pagination.Total)) + require.NoError(t, err) + require.Equal(t, len(msgs), int(resp.Pagination.Total)) }) t.Run("InvalidRequest", func(t *testing.T) { _, err := keeper.LastBlockHeightAll(wctx, nil) - assert.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) + require.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) }) } diff --git a/x/crosschain/keeper/grpc_query_out_tx_tracker_test.go b/x/crosschain/keeper/grpc_query_out_tx_tracker_test.go index 5951acf881..39f5ad3673 100644 --- a/x/crosschain/keeper/grpc_query_out_tx_tracker_test.go +++ b/x/crosschain/keeper/grpc_query_out_tx_tracker_test.go @@ -39,10 +39,10 @@ package keeper_test // t.Run(tc.desc, func(t *testing.T) { // response, err := keeper.OutTxTracker(wctx, tc.request) // if tc.err != nil { -// assert.ErrorIs(t, err, tc.err) +// require.ErrorIs(t, err, tc.err) // } else { -// assert.NoError(t, err) -// assert.Equal(t, +// require.NoError(t, err) +// require.Equal(t, // nullify.Fill(tc.response), // nullify.Fill(response), // ) @@ -70,9 +70,9 @@ package keeper_test // step := 2 // for i := 0; i < len(msgs); i += step { // resp, err := keeper.OutTxTrackerAll(wctx, request(nil, uint64(i), uint64(step), false)) -// assert.NoError(t, err) -// assert.LessOrEqual(t, len(resp.OutTxTracker), step) -// assert.Subset(t, +// require.NoError(t, err) +// require.LessOrEqual(t, len(resp.OutTxTracker), step) +// require.Subset(t, // nullify.Fill(msgs), // nullify.Fill(resp.OutTxTracker), // ) @@ -83,9 +83,9 @@ package keeper_test // var next []byte // for i := 0; i < len(msgs); i += step { // resp, err := keeper.OutTxTrackerAll(wctx, request(next, 0, uint64(step), false)) -// assert.NoError(t, err) -// assert.LessOrEqual(t, len(resp.OutTxTracker), step) -// assert.Subset(t, +// require.NoError(t, err) +// require.LessOrEqual(t, len(resp.OutTxTracker), step) +// require.Subset(t, // nullify.Fill(msgs), // nullify.Fill(resp.OutTxTracker), // ) @@ -94,15 +94,15 @@ package keeper_test // }) // t.Run("Total", func(t *testing.T) { // resp, err := keeper.OutTxTrackerAll(wctx, request(nil, 0, 0, true)) -// assert.NoError(t, err) -// assert.Equal(t, len(msgs), int(resp.Pagination.Total)) -// assert.ElementsMatch(t, +// require.NoError(t, err) +// require.Equal(t, len(msgs), int(resp.Pagination.Total)) +// require.ElementsMatch(t, // nullify.Fill(msgs), // nullify.Fill(resp.OutTxTracker), // ) // }) // t.Run("InvalidRequest", func(t *testing.T) { // _, err := keeper.OutTxTrackerAll(wctx, nil) -// assert.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) +// require.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) // }) //} diff --git a/x/crosschain/keeper/in_tx_hash_to_cctx_test.go b/x/crosschain/keeper/in_tx_hash_to_cctx_test.go index 2084724f44..6eb0118cf9 100644 --- a/x/crosschain/keeper/in_tx_hash_to_cctx_test.go +++ b/x/crosschain/keeper/in_tx_hash_to_cctx_test.go @@ -7,7 +7,7 @@ import ( "github.com/zeta-chain/zetacore/x/crosschain/keeper" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/nullify" "github.com/zeta-chain/zetacore/x/crosschain/types" @@ -30,8 +30,8 @@ func TestInTxHashToCctxGet(t *testing.T) { rst, found := keeper.GetInTxHashToCctx(ctx, item.InTxHash, ) - assert.True(t, found) - assert.Equal(t, + require.True(t, found) + require.Equal(t, nullify.Fill(&item), nullify.Fill(&rst), ) @@ -47,14 +47,14 @@ func TestInTxHashToCctxRemove(t *testing.T) { _, found := keeper.GetInTxHashToCctx(ctx, item.InTxHash, ) - assert.False(t, found) + require.False(t, found) } } func TestInTxHashToCctxGetAll(t *testing.T) { keeper, ctx, _, _ := keepertest.CrosschainKeeper(t) items := createNInTxHashToCctx(keeper, ctx, 10) - assert.ElementsMatch(t, + require.ElementsMatch(t, nullify.Fill(items), nullify.Fill(keeper.GetAllInTxHashToCctx(ctx)), ) diff --git a/x/crosschain/keeper/in_tx_tracker_test.go b/x/crosschain/keeper/in_tx_tracker_test.go index 841e4a2326..a4bda41192 100644 --- a/x/crosschain/keeper/in_tx_tracker_test.go +++ b/x/crosschain/keeper/in_tx_tracker_test.go @@ -7,7 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/nullify" @@ -31,15 +31,15 @@ func TestKeeper_GetAllInTxTrackerForChain(t *testing.T) { intxTrackers := createNInTxTracker(keeper, ctx, 10, 5) for _, item := range intxTrackers { rst, found := keeper.GetInTxTracker(ctx, item.ChainId, item.TxHash) - assert.True(t, found) - assert.Equal(t, item, rst) + require.True(t, found) + require.Equal(t, item, rst) } }) t.Run("Get all InTx trackers", func(t *testing.T) { keeper, ctx, _, _ := keepertest.CrosschainKeeper(t) intxTrackers := createNInTxTracker(keeper, ctx, 10, 5) rst := keeper.GetAllInTxTracker(ctx) - assert.Equal(t, intxTrackers, rst) + require.Equal(t, intxTrackers, rst) }) t.Run("Get all InTx trackers for chain", func(t *testing.T) { keeper, ctx, _, _ := keepertest.CrosschainKeeper(t) @@ -51,39 +51,39 @@ func TestKeeper_GetAllInTxTrackerForChain(t *testing.T) { sort.SliceStable(intxTrackersNew, func(i, j int) bool { return intxTrackersNew[i].TxHash < intxTrackersNew[j].TxHash }) - assert.Equal(t, intxTrackersNew, rst) + require.Equal(t, intxTrackersNew, rst) }) t.Run("Get all InTx trackers for chain paginated by limit", func(t *testing.T) { keeper, ctx, _, _ := keepertest.CrosschainKeeper(t) intxTrackers := createNInTxTracker(keeper, ctx, 100, 6) rst, pageRes, err := keeper.GetAllInTxTrackerForChainPaginated(ctx, 6, &query.PageRequest{Limit: 10, CountTotal: true}) - assert.NoError(t, err) - assert.Subset(t, nullify.Fill(intxTrackers), nullify.Fill(rst)) - assert.Equal(t, len(intxTrackers), int(pageRes.Total)) + require.NoError(t, err) + require.Subset(t, nullify.Fill(intxTrackers), nullify.Fill(rst)) + require.Equal(t, len(intxTrackers), int(pageRes.Total)) }) t.Run("Get all InTx trackers for chain paginated by offset", func(t *testing.T) { keeper, ctx, _, _ := keepertest.CrosschainKeeper(t) intxTrackers := createNInTxTracker(keeper, ctx, 100, 6) rst, pageRes, err := keeper.GetAllInTxTrackerForChainPaginated(ctx, 6, &query.PageRequest{Offset: 10, CountTotal: true}) - assert.NoError(t, err) - assert.Subset(t, nullify.Fill(intxTrackers), nullify.Fill(rst)) - assert.Equal(t, len(intxTrackers), int(pageRes.Total)) + require.NoError(t, err) + require.Subset(t, nullify.Fill(intxTrackers), nullify.Fill(rst)) + require.Equal(t, len(intxTrackers), int(pageRes.Total)) }) t.Run("Get all InTx trackers paginated by limit", func(t *testing.T) { keeper, ctx, _, _ := keepertest.CrosschainKeeper(t) intxTrackers := append(createNInTxTracker(keeper, ctx, 10, 6), createNInTxTracker(keeper, ctx, 10, 7)...) rst, pageRes, err := keeper.GetAllInTxTrackerPaginated(ctx, &query.PageRequest{Limit: 20, CountTotal: true}) - assert.NoError(t, err) - assert.Subset(t, nullify.Fill(intxTrackers), nullify.Fill(rst)) - assert.Equal(t, len(intxTrackers), int(pageRes.Total)) + require.NoError(t, err) + require.Subset(t, nullify.Fill(intxTrackers), nullify.Fill(rst)) + require.Equal(t, len(intxTrackers), int(pageRes.Total)) }) t.Run("Get all InTx trackers paginated by offset", func(t *testing.T) { keeper, ctx, _, _ := keepertest.CrosschainKeeper(t) intxTrackers := append(createNInTxTracker(keeper, ctx, 100, 6), createNInTxTracker(keeper, ctx, 100, 7)...) rst, pageRes, err := keeper.GetAllInTxTrackerPaginated(ctx, &query.PageRequest{Offset: 10, CountTotal: true}) - assert.NoError(t, err) - assert.Subset(t, nullify.Fill(intxTrackers), nullify.Fill(rst)) - assert.Equal(t, len(intxTrackers), int(pageRes.Total)) + require.NoError(t, err) + require.Subset(t, nullify.Fill(intxTrackers), nullify.Fill(rst)) + require.Equal(t, len(intxTrackers), int(pageRes.Total)) }) t.Run("Delete InTxTracker", func(t *testing.T) { keeper, ctx, _, _ := keepertest.CrosschainKeeper(t) @@ -98,6 +98,6 @@ func TestKeeper_GetAllInTxTrackerForChain(t *testing.T) { keeper.RemoveInTxTrackerIfExists(ctx, item.ChainId, item.TxHash) } rst := keeper.GetAllInTxTrackerForChain(ctx, 6) - assert.Equal(t, 0, len(rst)) + require.Equal(t, 0, len(rst)) }) } diff --git a/x/crosschain/keeper/keeper_test.go b/x/crosschain/keeper/keeper_test.go index 7bc0af5fb1..3a65063a16 100644 --- a/x/crosschain/keeper/keeper_test.go +++ b/x/crosschain/keeper/keeper_test.go @@ -12,7 +12,7 @@ import ( bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" typesparams "github.com/cosmos/cosmos-sdk/x/params/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/libs/log" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmdb "github.com/tendermint/tm-db" @@ -29,7 +29,7 @@ func setupKeeper(t testing.TB) (*Keeper, sdk.Context) { stateStore := store.NewCommitMultiStore(db) stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db) stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil) - assert.NoError(t, stateStore.LoadLatestVersion()) + require.NoError(t, stateStore.LoadLatestVersion()) registry := codectypes.NewInterfaceRegistry() cdc := codec.NewProtoCodec(registry) diff --git a/x/crosschain/keeper/last_block_height_test.go b/x/crosschain/keeper/last_block_height_test.go index 94eb087e01..8a284f6f97 100644 --- a/x/crosschain/keeper/last_block_height_test.go +++ b/x/crosschain/keeper/last_block_height_test.go @@ -5,7 +5,7 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/x/crosschain/types" ) @@ -24,8 +24,8 @@ func TestLastBlockHeightGet(t *testing.T) { items := createNLastBlockHeight(keeper, ctx, 10) for _, item := range items { rst, found := keeper.GetLastBlockHeight(ctx, item.Index) - assert.True(t, found) - assert.Equal(t, item, rst) + require.True(t, found) + require.Equal(t, item, rst) } } func TestLastBlockHeightRemove(t *testing.T) { @@ -34,12 +34,12 @@ func TestLastBlockHeightRemove(t *testing.T) { for _, item := range items { keeper.RemoveLastBlockHeight(ctx, item.Index) _, found := keeper.GetLastBlockHeight(ctx, item.Index) - assert.False(t, found) + require.False(t, found) } } func TestLastBlockHeightGetAll(t *testing.T) { keeper, ctx := setupKeeper(t) items := createNLastBlockHeight(keeper, ctx, 10) - assert.Equal(t, items, keeper.GetAllLastBlockHeight(ctx)) + require.Equal(t, items, keeper.GetAllLastBlockHeight(ctx)) } diff --git a/x/crosschain/keeper/msg_server_abort_stuck_cctx_test.go b/x/crosschain/keeper/msg_server_abort_stuck_cctx_test.go index 8a1953d3b8..f9b7c380e0 100644 --- a/x/crosschain/keeper/msg_server_abort_stuck_cctx_test.go +++ b/x/crosschain/keeper/msg_server_abort_stuck_cctx_test.go @@ -3,7 +3,7 @@ package keeper_test import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" crosschainkeeper "github.com/zeta-chain/zetacore/x/crosschain/keeper" @@ -32,11 +32,11 @@ func TestMsgServer_AbortStuckCCTX(t *testing.T) { CctxIndex: "cctx_index", }) - assert.NoError(t, err) + require.NoError(t, err) cctxFound, found := k.GetCrossChainTx(ctx, "cctx_index") - assert.True(t, found) - assert.Equal(t, crosschaintypes.CctxStatus_Aborted, cctxFound.CctxStatus.Status) - assert.Equal(t, crosschainkeeper.AbortMessage, cctxFound.CctxStatus.StatusMessage) + require.True(t, found) + require.Equal(t, crosschaintypes.CctxStatus_Aborted, cctxFound.CctxStatus.Status) + require.Equal(t, crosschainkeeper.AbortMessage, cctxFound.CctxStatus.StatusMessage) }) t.Run("can abort a cctx in pending outbound", func(t *testing.T) { @@ -59,11 +59,11 @@ func TestMsgServer_AbortStuckCCTX(t *testing.T) { CctxIndex: "cctx_index", }) - assert.NoError(t, err) + require.NoError(t, err) cctxFound, found := k.GetCrossChainTx(ctx, "cctx_index") - assert.True(t, found) - assert.Equal(t, crosschaintypes.CctxStatus_Aborted, cctxFound.CctxStatus.Status) - assert.Equal(t, crosschainkeeper.AbortMessage, cctxFound.CctxStatus.StatusMessage) + require.True(t, found) + require.Equal(t, crosschaintypes.CctxStatus_Aborted, cctxFound.CctxStatus.Status) + require.Equal(t, crosschainkeeper.AbortMessage, cctxFound.CctxStatus.StatusMessage) }) t.Run("can abort a cctx in pending revert", func(t *testing.T) { @@ -86,11 +86,11 @@ func TestMsgServer_AbortStuckCCTX(t *testing.T) { CctxIndex: "cctx_index", }) - assert.NoError(t, err) + require.NoError(t, err) cctxFound, found := k.GetCrossChainTx(ctx, "cctx_index") - assert.True(t, found) - assert.Equal(t, crosschaintypes.CctxStatus_Aborted, cctxFound.CctxStatus.Status) - assert.Equal(t, crosschainkeeper.AbortMessage, cctxFound.CctxStatus.StatusMessage) + require.True(t, found) + require.Equal(t, crosschaintypes.CctxStatus_Aborted, cctxFound.CctxStatus.Status) + require.Equal(t, crosschainkeeper.AbortMessage, cctxFound.CctxStatus.StatusMessage) }) t.Run("cannot abort a cctx in pending outbound if not admin", func(t *testing.T) { @@ -110,7 +110,7 @@ func TestMsgServer_AbortStuckCCTX(t *testing.T) { Creator: sample.AccAddress(), CctxIndex: "cctx_index", }) - assert.ErrorIs(t, err, observertypes.ErrNotAuthorized) + require.ErrorIs(t, err, observertypes.ErrNotAuthorized) }) t.Run("cannot abort a cctx if doesn't exist", func(t *testing.T) { @@ -124,7 +124,7 @@ func TestMsgServer_AbortStuckCCTX(t *testing.T) { Creator: admin, CctxIndex: "cctx_index", }) - assert.ErrorIs(t, err, crosschaintypes.ErrCannotFindCctx) + require.ErrorIs(t, err, crosschaintypes.ErrCannotFindCctx) }) t.Run("cannot abort a cctx if not pending", func(t *testing.T) { @@ -146,6 +146,6 @@ func TestMsgServer_AbortStuckCCTX(t *testing.T) { Creator: admin, CctxIndex: "cctx_index", }) - assert.ErrorIs(t, err, crosschaintypes.ErrStatusNotPending) + require.ErrorIs(t, err, crosschaintypes.ErrStatusNotPending) }) } diff --git a/x/crosschain/keeper/msg_server_add_to_intx_tracker_test.go b/x/crosschain/keeper/msg_server_add_to_intx_tracker_test.go index f2b646017a..7457068b38 100644 --- a/x/crosschain/keeper/msg_server_add_to_intx_tracker_test.go +++ b/x/crosschain/keeper/msg_server_add_to_intx_tracker_test.go @@ -5,7 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" ethtypes "github.com/ethereum/go-ethereum/core/types" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -19,7 +19,7 @@ func TestMsgServer_AddToInTxTracker(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) chainID := int64(5) txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() - assert.NoError(t, err) + require.NoError(t, err) setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) msgServer := keeper.NewMsgServerImpl(*k) _, err = msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ @@ -31,16 +31,16 @@ func TestMsgServer_AddToInTxTracker(t *testing.T) { BlockHash: block.Hash().Hex(), TxIndex: txIndex, }) - assert.NoError(t, err) + require.NoError(t, err) _, found := k.GetInTxTracker(ctx, chainID, tx.Hash().Hex()) - assert.True(t, found) + require.True(t, found) }) t.Run("fail to add proof based tracker with wrong tx hash", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) chainID := getValidEthChainID(t) txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() - assert.NoError(t, err) + require.NoError(t, err) setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) msgServer := keeper.NewMsgServerImpl(*k) _, err = msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ @@ -52,16 +52,16 @@ func TestMsgServer_AddToInTxTracker(t *testing.T) { BlockHash: block.Hash().Hex(), TxIndex: txIndex, }) - assert.ErrorIs(t, err, types.ErrTxBodyVerificationFail) + require.ErrorIs(t, err, types.ErrTxBodyVerificationFail) _, found := k.GetInTxTracker(ctx, chainID, tx.Hash().Hex()) - assert.False(t, found) + require.False(t, found) }) t.Run("fail to add proof based tracker with wrong chain id", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) chainID := getValidEthChainID(t) txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() - assert.NoError(t, err) + require.NoError(t, err) setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) msgServer := keeper.NewMsgServerImpl(*k) _, err = msgServer.AddToInTxTracker(ctx, &types.MsgAddToInTxTracker{ @@ -73,9 +73,9 @@ func TestMsgServer_AddToInTxTracker(t *testing.T) { BlockHash: block.Hash().Hex(), TxIndex: txIndex, }) - assert.ErrorIs(t, err, observertypes.ErrSupportedChains) + require.ErrorIs(t, err, observertypes.ErrSupportedChains) _, found := k.GetInTxTracker(ctx, chainID, tx.Hash().Hex()) - assert.False(t, found) + require.False(t, found) }) t.Run("fail normal user submit without proof", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) @@ -92,9 +92,9 @@ func TestMsgServer_AddToInTxTracker(t *testing.T) { BlockHash: "", TxIndex: 0, }) - assert.ErrorIs(t, err, observertypes.ErrNotAuthorized) + require.ErrorIs(t, err, observertypes.ErrNotAuthorized) _, found := k.GetInTxTracker(ctx, chainID, tx_hash) - assert.False(t, found) + require.False(t, found) }) t.Run("admin add tx tracker", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) @@ -113,9 +113,9 @@ func TestMsgServer_AddToInTxTracker(t *testing.T) { BlockHash: "", TxIndex: 0, }) - assert.NoError(t, err) + require.NoError(t, err) _, found := k.GetInTxTracker(ctx, chainID, tx_hash) - assert.True(t, found) + require.True(t, found) }) t.Run("admin submit fake tracker", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) @@ -134,11 +134,11 @@ func TestMsgServer_AddToInTxTracker(t *testing.T) { BlockHash: "", TxIndex: 0, }) - assert.NoError(t, err) + require.NoError(t, err) _, found := k.GetInTxTracker(ctx, chainID, "Malicious TX HASH") - assert.True(t, found) + require.True(t, found) _, found = k.GetInTxTracker(ctx, chainID, tx_hash) - assert.False(t, found) + require.False(t, found) }) } diff --git a/x/crosschain/keeper/msg_server_add_to_outtx_tracker_test.go b/x/crosschain/keeper/msg_server_add_to_outtx_tracker_test.go index 7a39d34579..a6dfe317eb 100644 --- a/x/crosschain/keeper/msg_server_add_to_outtx_tracker_test.go +++ b/x/crosschain/keeper/msg_server_add_to_outtx_tracker_test.go @@ -4,7 +4,7 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" "github.com/zeta-chain/zetacore/common/ethereum" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" @@ -25,7 +25,7 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { setAdminPolicies(ctx, zk, admin) chainID := getEthereumChainID() txIndex, block, header, headerRLP, _, tx, err := sample.Proof() - assert.NoError(t, err) + require.NoError(t, err) setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) setupTssAndNonceToCctx(k, ctx, chainID, 0) msgServer := keeper.NewMsgServerImpl(*k) @@ -38,9 +38,9 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { TxIndex: 0, Nonce: 0, }) - assert.NoError(t, err) + require.NoError(t, err) _, found := k.GetOutTxTracker(ctx, chainID, 0) - assert.True(t, found) + require.True(t, found) }) t.Run("unable to add tracker admin exceeding maximum allowed length of hashlist without proof", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) @@ -48,7 +48,7 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { setAdminPolicies(ctx, zk, admin) chainID := getEthereumChainID() txIndex, block, header, headerRLP, _, tx, err := sample.Proof() - assert.NoError(t, err) + require.NoError(t, err) setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) setupTssAndNonceToCctx(k, ctx, chainID, 0) k.SetOutTxTracker(ctx, types.OutTxTracker{ @@ -77,17 +77,17 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { TxIndex: 0, Nonce: 0, }) - assert.NoError(t, err) + require.NoError(t, err) tracker, found := k.GetOutTxTracker(ctx, chainID, 0) - assert.True(t, found) - assert.Equal(t, 2, len(tracker.HashList)) + require.True(t, found) + require.Equal(t, 2, len(tracker.HashList)) }) t.Run("fail add proof based tracker with wrong chainID", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) chainID := getEthereumChainID() txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() - assert.NoError(t, err) + require.NoError(t, err) setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) setupTssAndNonceToCctx(k, ctx, chainID, int64(tx.Nonce())) msgServer := keeper.NewMsgServerImpl(*k) @@ -100,16 +100,16 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { TxIndex: txIndex, Nonce: tx.Nonce(), }) - assert.ErrorIs(t, err, observertypes.ErrSupportedChains) + require.ErrorIs(t, err, observertypes.ErrSupportedChains) _, found := k.GetOutTxTracker(ctx, chainID, tx.Nonce()) - assert.False(t, found) + require.False(t, found) }) t.Run("fail add proof based tracker with wrong nonce", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) chainID := getEthereumChainID() txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() - assert.NoError(t, err) + require.NoError(t, err) setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) setupTssAndNonceToCctx(k, ctx, chainID, 1) msgServer := keeper.NewMsgServerImpl(*k) @@ -122,16 +122,16 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { TxIndex: txIndex, Nonce: 1, }) - assert.ErrorIs(t, err, types.ErrTxBodyVerificationFail) + require.ErrorIs(t, err, types.ErrTxBodyVerificationFail) _, found := k.GetOutTxTracker(ctx, chainID, 1) - assert.False(t, found) + require.False(t, found) }) t.Run("fail add proof based tracker with wrong tx_hash", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) chainID := getEthereumChainID() txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() - assert.NoError(t, err) + require.NoError(t, err) setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) setupTssAndNonceToCctx(k, ctx, chainID, int64(tx.Nonce())) msgServer := keeper.NewMsgServerImpl(*k) @@ -144,16 +144,16 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { TxIndex: txIndex, Nonce: tx.Nonce(), }) - assert.ErrorIs(t, err, types.ErrTxBodyVerificationFail) + require.ErrorIs(t, err, types.ErrTxBodyVerificationFail) _, found := k.GetOutTxTracker(ctx, chainID, tx.Nonce()) - assert.False(t, found) + require.False(t, found) }) t.Run("fail proof based tracker with incorrect proof", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) chainID := getEthereumChainID() txIndex, block, header, headerRLP, _, tx, err := sample.Proof() - assert.NoError(t, err) + require.NoError(t, err) setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) setupTssAndNonceToCctx(k, ctx, chainID, int64(tx.Nonce())) msgServer := keeper.NewMsgServerImpl(*k) @@ -166,15 +166,15 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { TxIndex: txIndex, Nonce: tx.Nonce(), }) - assert.ErrorIs(t, err, types.ErrProofVerificationFail) + require.ErrorIs(t, err, types.ErrProofVerificationFail) _, found := k.GetOutTxTracker(ctx, chainID, tx.Nonce()) - assert.False(t, found) + require.False(t, found) }) t.Run("add proof based tracker with correct proof", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) chainID := getEthereumChainID() txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() - assert.NoError(t, err) + require.NoError(t, err) setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) setupTssAndNonceToCctx(k, ctx, chainID, int64(tx.Nonce())) msgServer := keeper.NewMsgServerImpl(*k) @@ -187,15 +187,15 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { TxIndex: txIndex, Nonce: tx.Nonce(), }) - assert.NoError(t, err) + require.NoError(t, err) _, found := k.GetOutTxTracker(ctx, chainID, tx.Nonce()) - assert.True(t, found) + require.True(t, found) }) t.Run("add proven txHash even if length of hashList is already 2", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) chainID := getEthereumChainID() txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() - assert.NoError(t, err) + require.NoError(t, err) setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) setupTssAndNonceToCctx(k, ctx, chainID, int64(tx.Nonce())) k.SetOutTxTracker(ctx, types.OutTxTracker{ @@ -224,20 +224,20 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { TxIndex: txIndex, Nonce: tx.Nonce(), }) - assert.NoError(t, err) + require.NoError(t, err) tracker, found := k.GetOutTxTracker(ctx, chainID, tx.Nonce()) - assert.True(t, found) - assert.Equal(t, 3, len(tracker.HashList)) + require.True(t, found) + require.Equal(t, 3, len(tracker.HashList)) // Proven tracker is prepended to the list - assert.True(t, tracker.HashList[0].Proved) - assert.False(t, tracker.HashList[1].Proved) - assert.False(t, tracker.HashList[2].Proved) + require.True(t, tracker.HashList[0].Proved) + require.False(t, tracker.HashList[1].Proved) + require.False(t, tracker.HashList[2].Proved) }) t.Run("add proof for existing txHash", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) chainID := getEthereumChainID() txIndex, block, header, headerRLP, proof, tx, err := sample.Proof() - assert.NoError(t, err) + require.NoError(t, err) setupVerificationParams(zk, ctx, txIndex, chainID, header, headerRLP, block) setupTssAndNonceToCctx(k, ctx, chainID, int64(tx.Nonce())) k.SetOutTxTracker(ctx, types.OutTxTracker{ @@ -252,8 +252,8 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { }, }) tracker, found := k.GetOutTxTracker(ctx, chainID, tx.Nonce()) - assert.True(t, found) - assert.False(t, tracker.HashList[0].Proved) + require.True(t, found) + require.False(t, tracker.HashList[0].Proved) msgServer := keeper.NewMsgServerImpl(*k) _, err = msgServer.AddToOutTxTracker(ctx, &types.MsgAddToOutTxTracker{ Creator: sample.AccAddress(), @@ -264,11 +264,11 @@ func TestMsgServer_AddToOutTxTracker(t *testing.T) { TxIndex: txIndex, Nonce: tx.Nonce(), }) - assert.NoError(t, err) + require.NoError(t, err) tracker, found = k.GetOutTxTracker(ctx, chainID, tx.Nonce()) - assert.True(t, found) - assert.Equal(t, 1, len(tracker.HashList)) - assert.True(t, tracker.HashList[0].Proved) + require.True(t, found) + require.Equal(t, 1, len(tracker.HashList)) + require.True(t, tracker.HashList[0].Proved) }) } diff --git a/x/crosschain/keeper/msg_server_migrate_tss_funds_test.go b/x/crosschain/keeper/msg_server_migrate_tss_funds_test.go index c8aadf0de4..4d909abdf0 100644 --- a/x/crosschain/keeper/msg_server_migrate_tss_funds_test.go +++ b/x/crosschain/keeper/msg_server_migrate_tss_funds_test.go @@ -6,7 +6,7 @@ import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/crypto" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -25,20 +25,20 @@ func TestKeeper_MigrateTSSFundsForChain(t *testing.T) { amount := sdkmath.NewUintFromString("10000000000000000000") indexString, _ := setupTssMigrationParams(zk, k, ctx, *chain, amount, true, true) gp, found := k.GetMedianGasPriceInUint(ctx, chain.ChainId) - assert.True(t, found) + require.True(t, found) _, err := msgServer.MigrateTssFunds(ctx, &crosschaintypes.MsgMigrateTssFunds{ Creator: admin, ChainId: chain.ChainId, Amount: amount, }) - assert.NoError(t, err) + require.NoError(t, err) hash := crypto.Keccak256Hash([]byte(indexString)) index := hash.Hex() cctx, found := k.GetCrossChainTx(ctx, index) - assert.True(t, found) + require.True(t, found) multipliedValue, err := common.MultiplyGasPrice(gp, crosschaintypes.TssMigrationGasMultiplierEVM) - assert.NoError(t, err) - assert.Equal(t, multipliedValue.String(), cctx.GetCurrentOutTxParam().OutboundTxGasPrice) + require.NoError(t, err) + require.Equal(t, multipliedValue.String(), cctx.GetCurrentOutTxParam().OutboundTxGasPrice) }) } @@ -56,14 +56,14 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { ChainId: chain.ChainId, Amount: amount, }) - assert.NoError(t, err) + require.NoError(t, err) hash := crypto.Keccak256Hash([]byte(indexString)) index := hash.Hex() cctx, found := k.GetCrossChainTx(ctx, index) - assert.True(t, found) + require.True(t, found) feeCalculated := sdk.NewUint(cctx.GetCurrentOutTxParam().OutboundTxGasLimit). Mul(sdkmath.NewUintFromString(cctx.GetCurrentOutTxParam().OutboundTxGasPrice)) - assert.Equal(t, cctx.GetCurrentOutTxParam().Amount.String(), amount.Sub(feeCalculated).String()) + require.Equal(t, cctx.GetCurrentOutTxParam().Amount.String(), amount.Sub(feeCalculated).String()) }) t.Run("not enough funds in tss address for migration", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) @@ -78,11 +78,11 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { ChainId: chain.ChainId, Amount: amount, }) - assert.ErrorContains(t, err, crosschaintypes.ErrCannotMigrateTssFunds.Error()) + require.ErrorContains(t, err, crosschaintypes.ErrCannotMigrateTssFunds.Error()) hash := crypto.Keccak256Hash([]byte(indexString)) index := hash.Hex() _, found := k.GetCrossChainTx(ctx, index) - assert.False(t, found) + require.False(t, found) }) t.Run("unable to migrate funds if new TSS is not created ", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) @@ -97,11 +97,11 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { ChainId: chain.ChainId, Amount: amount, }) - assert.ErrorContains(t, err, "no new tss address has been generated") + require.ErrorContains(t, err, "no new tss address has been generated") hash := crypto.Keccak256Hash([]byte(indexString)) index := hash.Hex() _, found := k.GetCrossChainTx(ctx, index) - assert.False(t, found) + require.False(t, found) }) t.Run("unable to migrate funds when nonce low does not match nonce high", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) @@ -122,12 +122,12 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { ChainId: chain.ChainId, Amount: amount, }) - assert.ErrorIs(t, err, crosschaintypes.ErrCannotMigrateTssFunds) - assert.ErrorContains(t, err, "cannot migrate funds when there are pending nonces") + require.ErrorIs(t, err, crosschaintypes.ErrCannotMigrateTssFunds) + require.ErrorContains(t, err, "cannot migrate funds when there are pending nonces") hash := crypto.Keccak256Hash([]byte(indexString)) index := hash.Hex() _, found := k.GetCrossChainTx(ctx, index) - assert.False(t, found) + require.False(t, found) }) t.Run("unable to migrate funds when a pending cctx is presnt in migration info", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) @@ -155,14 +155,14 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { ChainId: chain.ChainId, Amount: amount, }) - assert.ErrorIs(t, err, crosschaintypes.ErrCannotMigrateTssFunds) - assert.ErrorContains(t, err, "cannot migrate funds while there are pending migrations") + require.ErrorIs(t, err, crosschaintypes.ErrCannotMigrateTssFunds) + require.ErrorContains(t, err, "cannot migrate funds while there are pending migrations") hash := crypto.Keccak256Hash([]byte(indexString)) index := hash.Hex() _, found := k.GetCrossChainTx(ctx, index) - assert.False(t, found) + require.False(t, found) _, found = k.GetCrossChainTx(ctx, existingCctx.Index) - assert.True(t, found) + require.True(t, found) }) t.Run("unable to migrate funds if current TSS is not present in TSSHistory and no new TSS has been generated", func(t *testing.T) { @@ -174,7 +174,7 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { amount := sdkmath.NewUintFromString("10000000000000000000") indexString, _ := setupTssMigrationParams(zk, k, ctx, *chain, amount, false, false) currentTss, found := k.GetObserverKeeper().GetTSS(ctx) - assert.True(t, found) + require.True(t, found) newTss := sample.Tss() newTss.FinalizedZetaHeight = currentTss.FinalizedZetaHeight - 10 newTss.KeyGenZetaHeight = currentTss.KeyGenZetaHeight - 10 @@ -184,12 +184,12 @@ func TestMsgServer_MigrateTssFunds(t *testing.T) { ChainId: chain.ChainId, Amount: amount, }) - assert.ErrorIs(t, err, crosschaintypes.ErrCannotMigrateTssFunds) - assert.ErrorContains(t, err, "current tss is the latest") + require.ErrorIs(t, err, crosschaintypes.ErrCannotMigrateTssFunds) + require.ErrorContains(t, err, "current tss is the latest") hash := crypto.Keccak256Hash([]byte(indexString)) index := hash.Hex() _, found = k.GetCrossChainTx(ctx, index) - assert.False(t, found) + require.False(t, found) }) } func setupTssMigrationParams( diff --git a/x/crosschain/keeper/msg_server_update_tss_test.go b/x/crosschain/keeper/msg_server_update_tss_test.go index 6f9ff04e8e..d1cd4a0fef 100644 --- a/x/crosschain/keeper/msg_server_update_tss_test.go +++ b/x/crosschain/keeper/msg_server_update_tss_test.go @@ -3,7 +3,7 @@ package keeper_test import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -33,17 +33,17 @@ func TestMsgServer_UpdateTssAddress(t *testing.T) { cctx.CctxStatus.Status = crosschaintypes.CctxStatus_OutboundMined k.SetCrossChainTx(ctx, *cctx) } - assert.Equal(t, len(k.GetObserverKeeper().GetAllTssFundMigrators(ctx)), len(k.GetObserverKeeper().GetSupportedChains(ctx))) + require.Equal(t, len(k.GetObserverKeeper().GetAllTssFundMigrators(ctx)), len(k.GetObserverKeeper().GetSupportedChains(ctx))) _, err := msgServer.UpdateTssAddress(ctx, &crosschaintypes.MsgUpdateTssAddress{ Creator: admin, TssPubkey: tssNew.TssPubkey, }) - assert.NoError(t, err) + require.NoError(t, err) tss, found := k.GetObserverKeeper().GetTSS(ctx) - assert.True(t, found) - assert.Equal(t, tssNew, tss) + require.True(t, found) + require.Equal(t, tssNew, tss) migrators := k.GetObserverKeeper().GetAllTssFundMigrators(ctx) - assert.Equal(t, 0, len(migrators)) + require.Equal(t, 0, len(migrators)) }) t.Run("new tss has not been added to tss history", func(t *testing.T) { @@ -65,17 +65,17 @@ func TestMsgServer_UpdateTssAddress(t *testing.T) { cctx.CctxStatus.Status = crosschaintypes.CctxStatus_OutboundMined k.SetCrossChainTx(ctx, *cctx) } - assert.Equal(t, len(k.GetObserverKeeper().GetAllTssFundMigrators(ctx)), len(k.GetObserverKeeper().GetSupportedChains(ctx))) + require.Equal(t, len(k.GetObserverKeeper().GetAllTssFundMigrators(ctx)), len(k.GetObserverKeeper().GetSupportedChains(ctx))) _, err := msgServer.UpdateTssAddress(ctx, &crosschaintypes.MsgUpdateTssAddress{ Creator: admin, TssPubkey: tssNew.TssPubkey, }) - assert.ErrorContains(t, err, "tss pubkey has not been generated") - assert.ErrorIs(t, err, crosschaintypes.ErrUnableToUpdateTss) + require.ErrorContains(t, err, "tss pubkey has not been generated") + require.ErrorIs(t, err, crosschaintypes.ErrUnableToUpdateTss) tss, found := k.GetObserverKeeper().GetTSS(ctx) - assert.True(t, found) - assert.Equal(t, tssOld, tss) - assert.Equal(t, len(k.GetObserverKeeper().GetAllTssFundMigrators(ctx)), len(k.GetObserverKeeper().GetSupportedChains(ctx))) + require.True(t, found) + require.Equal(t, tssOld, tss) + require.Equal(t, len(k.GetObserverKeeper().GetAllTssFundMigrators(ctx)), len(k.GetObserverKeeper().GetSupportedChains(ctx))) }) t.Run("old tss pubkey provided", func(t *testing.T) { @@ -96,17 +96,17 @@ func TestMsgServer_UpdateTssAddress(t *testing.T) { cctx.CctxStatus.Status = crosschaintypes.CctxStatus_OutboundMined k.SetCrossChainTx(ctx, *cctx) } - assert.Equal(t, len(k.GetObserverKeeper().GetAllTssFundMigrators(ctx)), len(k.GetObserverKeeper().GetSupportedChains(ctx))) + require.Equal(t, len(k.GetObserverKeeper().GetAllTssFundMigrators(ctx)), len(k.GetObserverKeeper().GetSupportedChains(ctx))) _, err := msgServer.UpdateTssAddress(ctx, &crosschaintypes.MsgUpdateTssAddress{ Creator: admin, TssPubkey: tssOld.TssPubkey, }) - assert.ErrorContains(t, err, "no new tss address has been generated") - assert.ErrorIs(t, err, crosschaintypes.ErrUnableToUpdateTss) + require.ErrorContains(t, err, "no new tss address has been generated") + require.ErrorIs(t, err, crosschaintypes.ErrUnableToUpdateTss) tss, found := k.GetObserverKeeper().GetTSS(ctx) - assert.True(t, found) - assert.Equal(t, tssOld, tss) - assert.Equal(t, len(k.GetObserverKeeper().GetAllTssFundMigrators(ctx)), len(k.GetObserverKeeper().GetSupportedChains(ctx))) + require.True(t, found) + require.Equal(t, tssOld, tss) + require.Equal(t, len(k.GetObserverKeeper().GetAllTssFundMigrators(ctx)), len(k.GetObserverKeeper().GetSupportedChains(ctx))) }) t.Run("unable to update tss when not enough migrators are present", func(t *testing.T) { @@ -133,18 +133,18 @@ func TestMsgServer_UpdateTssAddress(t *testing.T) { cctx.CctxStatus.Status = crosschaintypes.CctxStatus_OutboundMined k.SetCrossChainTx(ctx, *cctx) - assert.Equal(t, len(k.GetObserverKeeper().GetAllTssFundMigrators(ctx)), 1) + require.Equal(t, len(k.GetObserverKeeper().GetAllTssFundMigrators(ctx)), 1) _, err := msgServer.UpdateTssAddress(ctx, &crosschaintypes.MsgUpdateTssAddress{ Creator: admin, TssPubkey: tssNew.TssPubkey, }) - assert.ErrorContains(t, err, "cannot update tss address not enough migrations have been created and completed") - assert.ErrorIs(t, err, crosschaintypes.ErrUnableToUpdateTss) + require.ErrorContains(t, err, "cannot update tss address not enough migrations have been created and completed") + require.ErrorIs(t, err, crosschaintypes.ErrUnableToUpdateTss) tss, found := k.GetObserverKeeper().GetTSS(ctx) - assert.True(t, found) - assert.Equal(t, tssOld, tss) + require.True(t, found) + require.Equal(t, tssOld, tss) migrators := k.GetObserverKeeper().GetAllTssFundMigrators(ctx) - assert.Equal(t, 1, len(migrators)) + require.Equal(t, 1, len(migrators)) }) t.Run("unable to update tss when pending cctx is present", func(t *testing.T) { @@ -170,18 +170,18 @@ func TestMsgServer_UpdateTssAddress(t *testing.T) { cctx.CctxStatus.Status = crosschaintypes.CctxStatus_PendingOutbound k.SetCrossChainTx(ctx, *cctx) } - assert.Equal(t, len(k.GetObserverKeeper().GetAllTssFundMigrators(ctx)), len(k.GetObserverKeeper().GetSupportedChains(ctx))) + require.Equal(t, len(k.GetObserverKeeper().GetAllTssFundMigrators(ctx)), len(k.GetObserverKeeper().GetSupportedChains(ctx))) _, err := msgServer.UpdateTssAddress(ctx, &crosschaintypes.MsgUpdateTssAddress{ Creator: admin, TssPubkey: tssNew.TssPubkey, }) - assert.ErrorContains(t, err, "cannot update tss address while there are pending migrations") - assert.ErrorIs(t, err, crosschaintypes.ErrUnableToUpdateTss) + require.ErrorContains(t, err, "cannot update tss address while there are pending migrations") + require.ErrorIs(t, err, crosschaintypes.ErrUnableToUpdateTss) tss, found := k.GetObserverKeeper().GetTSS(ctx) - assert.True(t, found) - assert.Equal(t, tssOld, tss) + require.True(t, found) + require.Equal(t, tssOld, tss) migrators := k.GetObserverKeeper().GetAllTssFundMigrators(ctx) - assert.Equal(t, len(k.GetObserverKeeper().GetSupportedChains(ctx)), len(migrators)) + require.Equal(t, len(k.GetObserverKeeper().GetSupportedChains(ctx)), len(migrators)) }) t.Run("unable to update tss cctx is not present", func(t *testing.T) { @@ -204,17 +204,17 @@ func TestMsgServer_UpdateTssAddress(t *testing.T) { MigrationCctxIndex: index, }) } - assert.Equal(t, len(k.GetObserverKeeper().GetAllTssFundMigrators(ctx)), len(k.GetObserverKeeper().GetSupportedChains(ctx))) + require.Equal(t, len(k.GetObserverKeeper().GetAllTssFundMigrators(ctx)), len(k.GetObserverKeeper().GetSupportedChains(ctx))) _, err := msgServer.UpdateTssAddress(ctx, &crosschaintypes.MsgUpdateTssAddress{ Creator: admin, TssPubkey: tssNew.TssPubkey, }) - assert.ErrorContains(t, err, "migration cross chain tx not found") - assert.ErrorIs(t, err, crosschaintypes.ErrUnableToUpdateTss) + require.ErrorContains(t, err, "migration cross chain tx not found") + require.ErrorIs(t, err, crosschaintypes.ErrUnableToUpdateTss) tss, found := k.GetObserverKeeper().GetTSS(ctx) - assert.True(t, found) - assert.Equal(t, tssOld, tss) + require.True(t, found) + require.Equal(t, tssOld, tss) migrators := k.GetObserverKeeper().GetAllTssFundMigrators(ctx) - assert.Equal(t, len(k.GetObserverKeeper().GetSupportedChains(ctx)), len(migrators)) + require.Equal(t, len(k.GetObserverKeeper().GetSupportedChains(ctx)), len(migrators)) }) } diff --git a/x/crosschain/keeper/msg_server_vote_inbound_tx_test.go b/x/crosschain/keeper/msg_server_vote_inbound_tx_test.go index 32a0578ed8..c484b585d3 100644 --- a/x/crosschain/keeper/msg_server_vote_inbound_tx_test.go +++ b/x/crosschain/keeper/msg_server_vote_inbound_tx_test.go @@ -7,7 +7,7 @@ import ( //"github.com/zeta-chain/zetacore/common" sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -23,9 +23,9 @@ func setObservers(t *testing.T, k *keeper.Keeper, ctx sdk.Context, zk keepertest validatorAddressListFormatted := make([]string, len(validators)) for i, validator := range validators { valAddr, err := sdk.ValAddressFromBech32(validator.OperatorAddress) - assert.NoError(t, err) + require.NoError(t, err) addressTmp, err := sdk.AccAddressFromHexUnsafe(hex.EncodeToString(valAddr.Bytes())) - assert.NoError(t, err) + require.NoError(t, err) validatorAddressListFormatted[i] = addressTmp.String() } @@ -57,14 +57,14 @@ func TestKeeper_VoteOnObservedInboundTx(t *testing.T) { ctx, &msg, ) - assert.NoError(t, err) + require.NoError(t, err) } ballot, _, _ := zk.ObserverKeeper.FindBallot(ctx, msg.Digest(), zk.ObserverKeeper.GetSupportedChainFromChainID(ctx, msg.SenderChainId), observerTypes.ObservationType_InBoundTx) - assert.Equal(t, ballot.BallotStatus, observerTypes.BallotStatus_BallotFinalized_SuccessObservation) + require.Equal(t, ballot.BallotStatus, observerTypes.BallotStatus_BallotFinalized_SuccessObservation) cctx, found := k.GetCrossChainTx(ctx, msg.Digest()) - assert.True(t, found) - assert.Equal(t, cctx.CctxStatus.Status, types.CctxStatus_OutboundMined) - assert.Equal(t, cctx.InboundTxParams.TxFinalizationStatus, types.TxFinalizationStatus_Executed) + require.True(t, found) + require.Equal(t, cctx.CctxStatus.Status, types.CctxStatus_OutboundMined) + require.Equal(t, cctx.InboundTxParams.TxFinalizationStatus, types.TxFinalizationStatus_Executed) }) // TODO : https://github.com/zeta-chain/node/issues/1542 } @@ -117,12 +117,12 @@ func TestNoDoubleEventProtections(t *testing.T) { ctx, msg, ) - assert.NoError(t, err) + require.NoError(t, err) // Check that the vote passed ballot, found := zk.ObserverKeeper.GetBallot(ctx, msg.Digest()) - assert.True(t, found) - assert.Equal(t, ballot.BallotStatus, observerTypes.BallotStatus_BallotFinalized_SuccessObservation) + require.True(t, found) + require.Equal(t, ballot.BallotStatus, observerTypes.BallotStatus_BallotFinalized_SuccessObservation) //Perform the SAME event. Except, this time, we resubmit the event. msg2 := &types.MsgVoteOnObservedInboundTx{ Creator: validatorAddr, @@ -145,9 +145,9 @@ func TestNoDoubleEventProtections(t *testing.T) { ctx, msg2, ) - assert.ErrorIs(t, err, types.ErrObservedTxAlreadyFinalized) + require.ErrorIs(t, err, types.ErrObservedTxAlreadyFinalized) _, found = zk.ObserverKeeper.GetBallot(ctx, msg2.Digest()) - assert.False(t, found) + require.False(t, found) } func TestStatus_StatusTransition(t *testing.T) { tt := []struct { @@ -188,9 +188,9 @@ func TestStatus_StatusTransition(t *testing.T) { t.Run(test.Name, func(t *testing.T) { test.Status.ChangeStatus(test.NonErrStatus, test.Msg) if test.IsErr { - assert.Equal(t, test.ErrStatus, test.Status.Status) + require.Equal(t, test.ErrStatus, test.Status.Status) } else { - assert.Equal(t, test.NonErrStatus, test.Status.Status) + require.Equal(t, test.NonErrStatus, test.Status.Status) } }) } diff --git a/x/crosschain/keeper/msg_server_vote_outbound_tx_test.go b/x/crosschain/keeper/msg_server_vote_outbound_tx_test.go index 0f1c15ac17..b5ad6ab78d 100644 --- a/x/crosschain/keeper/msg_server_vote_outbound_tx_test.go +++ b/x/crosschain/keeper/msg_server_vote_outbound_tx_test.go @@ -7,7 +7,7 @@ import ( "testing" "cosmossdk.io/math" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" testkeeper "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/crosschain/keeper" @@ -102,10 +102,10 @@ func TestKeeper_FundGasStabilityPoolFromRemainingFees(t *testing.T) { err := k.FundGasStabilityPoolFromRemainingFees(ctx, *outbound, 42) if tc.isError { - assert.Error(t, err) + require.Error(t, err) return } - assert.NoError(t, err) + require.NoError(t, err) fungibleMock.AssertExpectations(t) }) diff --git a/x/crosschain/keeper/msg_server_whitelist_erc20_test.go b/x/crosschain/keeper/msg_server_whitelist_erc20_test.go index 324ac6ff02..82cd292fb2 100644 --- a/x/crosschain/keeper/msg_server_whitelist_erc20_test.go +++ b/x/crosschain/keeper/msg_server_whitelist_erc20_test.go @@ -6,7 +6,7 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ethcommon "github.com/ethereum/go-ethereum/common" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -45,25 +45,25 @@ func TestKeeper_WhitelistERC20(t *testing.T) { Decimals: 18, GasLimit: 100000, }) - assert.NoError(t, err) - assert.NotNil(t, res) + require.NoError(t, err) + require.NotNil(t, res) zrc20 := res.Zrc20Address cctxIndex := res.CctxIndex // check zrc20 and cctx created assertContractDeployment(t, sdkk.EvmKeeper, ctx, ethcommon.HexToAddress(zrc20)) fc, found := zk.FungibleKeeper.GetForeignCoins(ctx, zrc20) - assert.True(t, found) - assert.EqualValues(t, "foo", fc.Name) - assert.EqualValues(t, erc20Address, fc.Asset) + require.True(t, found) + require.EqualValues(t, "foo", fc.Name) + require.EqualValues(t, erc20Address, fc.Asset) cctx, found := k.GetCrossChainTx(ctx, cctxIndex) - assert.True(t, found) - assert.EqualValues(t, fmt.Sprintf("%s:%s", common.CmdWhitelistERC20, erc20Address), cctx.RelayedMessage) + require.True(t, found) + require.EqualValues(t, fmt.Sprintf("%s:%s", common.CmdWhitelistERC20, erc20Address), cctx.RelayedMessage) // check gas limit is set gasLimit, err := zk.FungibleKeeper.QueryGasLimit(ctx, ethcommon.HexToAddress(zrc20)) - assert.NoError(t, err) - assert.Equal(t, uint64(100000), gasLimit.Uint64()) + require.NoError(t, err) + require.Equal(t, uint64(100000), gasLimit.Uint64()) // Ensure that whitelist a new erc20 create a cctx with a different index res, err = msgServer.WhitelistERC20(ctx, &types.MsgWhitelistERC20{ @@ -75,9 +75,9 @@ func TestKeeper_WhitelistERC20(t *testing.T) { Decimals: 18, GasLimit: 100000, }) - assert.NoError(t, err) - assert.NotNil(t, res) - assert.NotEqual(t, cctxIndex, res.CctxIndex) + require.NoError(t, err) + require.NotNil(t, res) + require.NotEqual(t, cctxIndex, res.CctxIndex) }) t.Run("should fail if not authorized", func(t *testing.T) { @@ -94,7 +94,7 @@ func TestKeeper_WhitelistERC20(t *testing.T) { Decimals: 18, GasLimit: 100000, }) - assert.ErrorIs(t, err, sdkerrors.ErrUnauthorized) + require.ErrorIs(t, err, sdkerrors.ErrUnauthorized) }) t.Run("should fail if invalid erc20 address", func(t *testing.T) { @@ -114,7 +114,7 @@ func TestKeeper_WhitelistERC20(t *testing.T) { Decimals: 18, GasLimit: 100000, }) - assert.ErrorIs(t, err, sdkerrors.ErrInvalidAddress) + require.ErrorIs(t, err, sdkerrors.ErrInvalidAddress) }) t.Run("should fail if foreign coin already exists for the asset", func(t *testing.T) { @@ -141,7 +141,7 @@ func TestKeeper_WhitelistERC20(t *testing.T) { Decimals: 18, GasLimit: 100000, }) - assert.ErrorIs(t, err, fungibletypes.ErrForeignCoinAlreadyExist) + require.ErrorIs(t, err, fungibletypes.ErrForeignCoinAlreadyExist) }) t.Run("should fail if no tss set", func(t *testing.T) { @@ -163,7 +163,7 @@ func TestKeeper_WhitelistERC20(t *testing.T) { Decimals: 18, GasLimit: 100000, }) - assert.ErrorIs(t, err, types.ErrCannotFindTSSKeys) + require.ErrorIs(t, err, types.ErrCannotFindTSSKeys) }) t.Run("should fail if nox valid chain ID", func(t *testing.T) { @@ -185,6 +185,6 @@ func TestKeeper_WhitelistERC20(t *testing.T) { Decimals: 18, GasLimit: 100000, }) - assert.ErrorIs(t, err, types.ErrInvalidChainID) + require.ErrorIs(t, err, types.ErrInvalidChainID) }) } diff --git a/x/crosschain/keeper/out_tx_tracker_test.go b/x/crosschain/keeper/out_tx_tracker_test.go index 5644d30db4..4b849b4c3d 100644 --- a/x/crosschain/keeper/out_tx_tracker_test.go +++ b/x/crosschain/keeper/out_tx_tracker_test.go @@ -5,7 +5,7 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/nullify" "github.com/zeta-chain/zetacore/x/crosschain/keeper" @@ -33,8 +33,8 @@ func TestOutTxTrackerGet(t *testing.T) { item.ChainId, item.Nonce, ) - assert.True(t, found) - assert.Equal(t, + require.True(t, found) + require.Equal(t, nullify.Fill(&item), nullify.Fill(&rst), ) @@ -52,14 +52,14 @@ func TestOutTxTrackerRemove(t *testing.T) { item.ChainId, item.Nonce, ) - assert.False(t, found) + require.False(t, found) } } func TestOutTxTrackerGetAll(t *testing.T) { keeper, ctx, _, _ := keepertest.CrosschainKeeper(t) items := createNOutTxTracker(keeper, ctx, 10) - assert.ElementsMatch(t, + require.ElementsMatch(t, nullify.Fill(items), nullify.Fill(keeper.GetAllOutTxTracker(ctx)), ) diff --git a/x/crosschain/keeper/utils_test.go b/x/crosschain/keeper/utils_test.go index 088d10e604..d878b690d5 100644 --- a/x/crosschain/keeper/utils_test.go +++ b/x/crosschain/keeper/utils_test.go @@ -12,7 +12,7 @@ import ( bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" "github.com/ethereum/go-ethereum/common" evmkeeper "github.com/evmos/ethermint/x/evm/keeper" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/protocol-contracts/pkg/uniswap/v2-periphery/contracts/uniswapv2router02.sol" "github.com/zeta-chain/zetacore/cmd/zetacored/config" zetacommon "github.com/zeta-chain/zetacore/common" @@ -40,18 +40,18 @@ func getValidEthChainIDWithIndex(t *testing.T, index int) int64 { case 1: return zetacommon.GoerliChain().ChainId default: - assert.Fail(t, "invalid index") + require.Fail(t, "invalid index") } return 0 } -// assert that a contract has been deployed by checking stored code is non-empty. +// require that a contract has been deployed by checking stored code is non-empty. func assertContractDeployment(t *testing.T, k *evmkeeper.Keeper, ctx sdk.Context, contractAddress common.Address) { acc := k.GetAccount(ctx, contractAddress) - assert.NotNil(t, acc) + require.NotNil(t, acc) code := k.GetCode(ctx, common.BytesToHash(acc.CodeHash)) - assert.NotEmpty(t, code) + require.NotEmpty(t, code) } // deploySystemContracts deploys the system contracts and returns their addresses. @@ -64,28 +64,28 @@ func deploySystemContracts( var err error wzeta, err = k.DeployWZETA(ctx) - assert.NoError(t, err) - assert.NotEmpty(t, wzeta) + require.NoError(t, err) + require.NotEmpty(t, wzeta) assertContractDeployment(t, evmk, ctx, wzeta) uniswapV2Factory, err = k.DeployUniswapV2Factory(ctx) - assert.NoError(t, err) - assert.NotEmpty(t, uniswapV2Factory) + require.NoError(t, err) + require.NotEmpty(t, uniswapV2Factory) assertContractDeployment(t, evmk, ctx, uniswapV2Factory) uniswapV2Router, err = k.DeployUniswapV2Router02(ctx, uniswapV2Factory, wzeta) - assert.NoError(t, err) - assert.NotEmpty(t, uniswapV2Router) + require.NoError(t, err) + require.NotEmpty(t, uniswapV2Router) assertContractDeployment(t, evmk, ctx, uniswapV2Router) connector, err = k.DeployConnectorZEVM(ctx, wzeta) - assert.NoError(t, err) - assert.NotEmpty(t, connector) + require.NoError(t, err) + require.NotEmpty(t, connector) assertContractDeployment(t, evmk, ctx, connector) systemContract, err = k.DeploySystemContract(ctx, wzeta, uniswapV2Factory, uniswapV2Router) - assert.NoError(t, err) - assert.NotEmpty(t, systemContract) + require.NoError(t, err) + require.NotEmpty(t, systemContract) assertContractDeployment(t, evmk, ctx, systemContract) return @@ -109,7 +109,7 @@ func setupGasCoin( 8, nil, ) - assert.NoError(t, err) + require.NoError(t, err) assertContractDeployment(t, evmk, ctx, addr) return addr } @@ -135,7 +135,7 @@ func deployZRC20( assetAddress, big.NewInt(21_000), ) - assert.NoError(t, err) + require.NoError(t, err) assertContractDeployment(t, evmk, ctx, addr) return addr } @@ -149,22 +149,22 @@ func setupZRC20Pool( zrc20Addr common.Address, ) { routerAddress, err := k.GetUniswapV2Router02Address(ctx) - assert.NoError(t, err) + require.NoError(t, err) routerABI, err := uniswapv2router02.UniswapV2Router02MetaData.GetAbi() - assert.NoError(t, err) + require.NoError(t, err) // enough for the small numbers used in test liquidityAmount := big.NewInt(1e17) // mint some zrc20 and zeta _, err = k.DepositZRC20(ctx, zrc20Addr, types.ModuleAddressEVM, liquidityAmount) - assert.NoError(t, err) + require.NoError(t, err) err = bankKeeper.MintCoins( ctx, types.ModuleName, sdk.NewCoins(sdk.NewCoin(config.BaseDenom, sdk.NewIntFromBigInt(liquidityAmount))), ) - assert.NoError(t, err) + require.NoError(t, err) // approve the router to spend the zeta err = k.CallZRC20Approve( @@ -175,7 +175,7 @@ func setupZRC20Pool( liquidityAmount, false, ) - assert.NoError(t, err) + require.NoError(t, err) // add the liquidity //function addLiquidityETH( @@ -203,7 +203,7 @@ func setupZRC20Pool( types.ModuleAddressEVM, liquidityAmount, ) - assert.NoError(t, err) + require.NoError(t, err) } // setAdminPolicies sets the admin policies for the observer module with group 1 and 2 diff --git a/x/crosschain/keeper/zeta_accounting_test.go b/x/crosschain/keeper/zeta_accounting_test.go index a20ada338c..1d5e1f7921 100644 --- a/x/crosschain/keeper/zeta_accounting_test.go +++ b/x/crosschain/keeper/zeta_accounting_test.go @@ -5,7 +5,7 @@ import ( "testing" sdkmath "cosmossdk.io/math" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/x/crosschain/types" ) @@ -19,20 +19,20 @@ func TestKeeper_AddZetaAccounting(t *testing.T) { AbortedZetaAmount: originalAmount, }) val, found := k.GetZetaAccounting(ctx) - assert.True(t, found) - assert.Equal(t, originalAmount, val.AbortedZetaAmount) + require.True(t, found) + require.Equal(t, originalAmount, val.AbortedZetaAmount) addAmount := sdkmath.NewUint(rand.Uint64()) k.AddZetaAbortedAmount(ctx, addAmount) val, found = k.GetZetaAccounting(ctx) - assert.True(t, found) - assert.Equal(t, originalAmount.Add(addAmount), val.AbortedZetaAmount) + require.True(t, found) + require.Equal(t, originalAmount.Add(addAmount), val.AbortedZetaAmount) }) t.Run("cant find aborted amount", func(t *testing.T) { k, ctx, _, _ := keepertest.CrosschainKeeper(t) val, found := k.GetZetaAccounting(ctx) - assert.False(t, found) - assert.Equal(t, types.ZetaAccounting{}, val) + require.False(t, found) + require.Equal(t, types.ZetaAccounting{}, val) }) t.Run("add very high zeta amount", func(t *testing.T) { @@ -42,8 +42,8 @@ func TestKeeper_AddZetaAccounting(t *testing.T) { AbortedZetaAmount: highAmount, }) val, found := k.GetZetaAccounting(ctx) - assert.True(t, found) - assert.Equal(t, highAmount, val.AbortedZetaAmount) + require.True(t, found) + require.Equal(t, highAmount, val.AbortedZetaAmount) }) } diff --git a/x/crosschain/migrations/v4/migrate_test.go b/x/crosschain/migrations/v4/migrate_test.go index 98c005c4c8..d377f1a6fa 100644 --- a/x/crosschain/migrations/v4/migrate_test.go +++ b/x/crosschain/migrations/v4/migrate_test.go @@ -9,7 +9,7 @@ import ( sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -24,10 +24,10 @@ func TestMigrateStore(t *testing.T) { k, ctx, _, _ := keepertest.CrosschainKeeper(t) amountZeta := SetRandomCctx(ctx, *k) err := v4.MigrateStore(ctx, k.GetObserverKeeper(), k) - assert.NoError(t, err) + require.NoError(t, err) zetaAccounting, found := k.GetZetaAccounting(ctx) - assert.True(t, found) - assert.Equal(t, amountZeta, zetaAccounting.AbortedZetaAmount) + require.True(t, found) + require.Equal(t, amountZeta, zetaAccounting.AbortedZetaAmount) }) t.Run("test migrate store move tss from cross chain to observer", func(t *testing.T) { k, ctx, _, zk := keepertest.CrosschainKeeper(t) @@ -45,15 +45,15 @@ func TestMigrateStore(t *testing.T) { store.Set(observertypes.KeyPrefix(fmt.Sprintf("%d", tss2.FinalizedZetaHeight)), tss2Bytes) err := v4.MigrateStore(ctx, k.GetObserverKeeper(), k) - assert.NoError(t, err) + require.NoError(t, err) tss, found := zk.ObserverKeeper.GetTSS(ctx) - assert.True(t, found) - assert.Equal(t, tss1, tss) + require.True(t, found) + require.Equal(t, tss1, tss) tssHistory := k.GetObserverKeeper().GetAllTSS(ctx) - assert.Equal(t, 2, len(tssHistory)) - assert.Equal(t, tss1, tssHistory[0]) - assert.Equal(t, tss2, tssHistory[1]) + require.Equal(t, 2, len(tssHistory)) + require.Equal(t, tss1, tssHistory[0]) + require.Equal(t, tss2, tssHistory[1]) }) t.Run("test migrate store move nonce from cross chain to observer", func(t *testing.T) { k, ctx, _, _ := keepertest.CrosschainKeeper(t) @@ -73,18 +73,18 @@ func TestMigrateStore(t *testing.T) { store.Set(types.KeyPrefix(fmt.Sprintf("%s-%d-%d", nonce.Tss, nonce.ChainId, nonce.Nonce)), k.GetCodec().MustMarshal(&nonce)) } err := v4.MigrateStore(ctx, k.GetObserverKeeper(), k) - assert.NoError(t, err) + require.NoError(t, err) pn, err := k.GetObserverKeeper().GetAllPendingNonces(ctx) - assert.NoError(t, err) + require.NoError(t, err) sort.Slice(pn, func(i, j int) bool { return pn[i].ChainId < pn[j].ChainId }) sort.Slice(pendingNonces, func(i, j int) bool { return pendingNonces[i].ChainId < pendingNonces[j].ChainId }) - assert.Equal(t, pendingNonces, pn) - assert.Equal(t, chainNonces, k.GetObserverKeeper().GetAllChainNonces(ctx)) - assert.Equal(t, nonceToCctxList, k.GetObserverKeeper().GetAllNonceToCctx(ctx)) + require.Equal(t, pendingNonces, pn) + require.Equal(t, chainNonces, k.GetObserverKeeper().GetAllChainNonces(ctx)) + require.Equal(t, nonceToCctxList, k.GetObserverKeeper().GetAllNonceToCctx(ctx)) }) } @@ -147,13 +147,13 @@ func TestSetBitcoinFinalizedInbound(t *testing.T) { v4.SetBitcoinFinalizedInbound(ctx, k) // check finalized inbound - assert.False(t, k.IsFinalizedInbound(ctx, "0xaaa", common.GoerliChain().ChainId, 0)) - assert.False(t, k.IsFinalizedInbound(ctx, "0xbbb", common.EthChain().ChainId, 0)) - assert.False(t, k.IsFinalizedInbound(ctx, "0xccc", common.MumbaiChain().ChainId, 0)) - assert.True(t, k.IsFinalizedInbound(ctx, "0x111", common.BtcMainnetChain().ChainId, 0)) - assert.True(t, k.IsFinalizedInbound(ctx, "0x222", common.BtcTestNetChain().ChainId, 0)) - assert.True(t, k.IsFinalizedInbound(ctx, "0x333", common.BtcTestNetChain().ChainId, 0)) - assert.True(t, k.IsFinalizedInbound(ctx, "0x444", common.BtcRegtestChain().ChainId, 0)) + require.False(t, k.IsFinalizedInbound(ctx, "0xaaa", common.GoerliChain().ChainId, 0)) + require.False(t, k.IsFinalizedInbound(ctx, "0xbbb", common.EthChain().ChainId, 0)) + require.False(t, k.IsFinalizedInbound(ctx, "0xccc", common.MumbaiChain().ChainId, 0)) + require.True(t, k.IsFinalizedInbound(ctx, "0x111", common.BtcMainnetChain().ChainId, 0)) + require.True(t, k.IsFinalizedInbound(ctx, "0x222", common.BtcTestNetChain().ChainId, 0)) + require.True(t, k.IsFinalizedInbound(ctx, "0x333", common.BtcTestNetChain().ChainId, 0)) + require.True(t, k.IsFinalizedInbound(ctx, "0x444", common.BtcRegtestChain().ChainId, 0)) }) } diff --git a/x/crosschain/types/cctx_utils_test.go b/x/crosschain/types/cctx_utils_test.go index 6c8be1561d..381ef47f6c 100644 --- a/x/crosschain/types/cctx_utils_test.go +++ b/x/crosschain/types/cctx_utils_test.go @@ -4,7 +4,7 @@ import ( "math/rand" "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/crosschain/types" ) @@ -14,13 +14,13 @@ func TestCrossChainTx_GetCurrentOutTxParam(t *testing.T) { cctx := sample.CrossChainTx(t, "foo") cctx.OutboundTxParams = []*types.OutboundTxParams{} - assert.Equal(t, &types.OutboundTxParams{}, cctx.GetCurrentOutTxParam()) + require.Equal(t, &types.OutboundTxParams{}, cctx.GetCurrentOutTxParam()) cctx.OutboundTxParams = []*types.OutboundTxParams{sample.OutboundTxParams(r)} - assert.Equal(t, cctx.OutboundTxParams[0], cctx.GetCurrentOutTxParam()) + require.Equal(t, cctx.OutboundTxParams[0], cctx.GetCurrentOutTxParam()) cctx.OutboundTxParams = []*types.OutboundTxParams{sample.OutboundTxParams(r), sample.OutboundTxParams(r)} - assert.Equal(t, cctx.OutboundTxParams[1], cctx.GetCurrentOutTxParam()) + require.Equal(t, cctx.OutboundTxParams[1], cctx.GetCurrentOutTxParam()) } func TestCrossChainTx_IsCurrentOutTxRevert(t *testing.T) { @@ -28,13 +28,13 @@ func TestCrossChainTx_IsCurrentOutTxRevert(t *testing.T) { cctx := sample.CrossChainTx(t, "foo") cctx.OutboundTxParams = []*types.OutboundTxParams{} - assert.False(t, cctx.IsCurrentOutTxRevert()) + require.False(t, cctx.IsCurrentOutTxRevert()) cctx.OutboundTxParams = []*types.OutboundTxParams{sample.OutboundTxParams(r)} - assert.False(t, cctx.IsCurrentOutTxRevert()) + require.False(t, cctx.IsCurrentOutTxRevert()) cctx.OutboundTxParams = []*types.OutboundTxParams{sample.OutboundTxParams(r), sample.OutboundTxParams(r)} - assert.True(t, cctx.IsCurrentOutTxRevert()) + require.True(t, cctx.IsCurrentOutTxRevert()) } func TestCrossChainTx_OriginalDestinationChainID(t *testing.T) { @@ -42,13 +42,13 @@ func TestCrossChainTx_OriginalDestinationChainID(t *testing.T) { cctx := sample.CrossChainTx(t, "foo") cctx.OutboundTxParams = []*types.OutboundTxParams{} - assert.Equal(t, int64(-1), cctx.OriginalDestinationChainID()) + require.Equal(t, int64(-1), cctx.OriginalDestinationChainID()) cctx.OutboundTxParams = []*types.OutboundTxParams{sample.OutboundTxParams(r)} - assert.Equal(t, cctx.OutboundTxParams[0].ReceiverChainId, cctx.OriginalDestinationChainID()) + require.Equal(t, cctx.OutboundTxParams[0].ReceiverChainId, cctx.OriginalDestinationChainID()) cctx.OutboundTxParams = []*types.OutboundTxParams{sample.OutboundTxParams(r), sample.OutboundTxParams(r)} - assert.Equal(t, cctx.OutboundTxParams[0].ReceiverChainId, cctx.OriginalDestinationChainID()) + require.Equal(t, cctx.OutboundTxParams[0].ReceiverChainId, cctx.OriginalDestinationChainID()) } func TestOutboundTxParams_GetGasPrice(t *testing.T) { @@ -58,10 +58,10 @@ func TestOutboundTxParams_GetGasPrice(t *testing.T) { outTxParams.OutboundTxGasPrice = "42" gasPrice, err := outTxParams.GetGasPrice() - assert.NoError(t, err) - assert.EqualValues(t, uint64(42), gasPrice) + require.NoError(t, err) + require.EqualValues(t, uint64(42), gasPrice) outTxParams.OutboundTxGasPrice = "invalid" _, err = outTxParams.GetGasPrice() - assert.Error(t, err) + require.Error(t, err) } diff --git a/x/crosschain/types/genesis_test.go b/x/crosschain/types/genesis_test.go index 9fe7a827ea..2b8b5eb80f 100644 --- a/x/crosschain/types/genesis_test.go +++ b/x/crosschain/types/genesis_test.go @@ -3,7 +3,7 @@ package types_test import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/x/crosschain/types" ) @@ -82,9 +82,9 @@ func TestGenesisState_Validate(t *testing.T) { t.Run(tc.desc, func(t *testing.T) { err := tc.genState.Validate() if tc.valid { - assert.NoError(t, err) + require.NoError(t, err) } else { - assert.Error(t, err) + require.Error(t, err) } }) } diff --git a/x/crosschain/types/message_abort_stuck_cctx_test.go b/x/crosschain/types/message_abort_stuck_cctx_test.go index 02eb7c50fd..40bdcf4794 100644 --- a/x/crosschain/types/message_abort_stuck_cctx_test.go +++ b/x/crosschain/types/message_abort_stuck_cctx_test.go @@ -4,7 +4,7 @@ import ( "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/crosschain/types" ) @@ -36,10 +36,10 @@ func TestMsgAbortStuckCCTX_ValidateBasic(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - assert.ErrorIs(t, err, tt.err) + require.ErrorIs(t, err, tt.err) return } - assert.NoError(t, err) + require.NoError(t, err) }) } } diff --git a/x/crosschain/types/message_add_to_in_tx_tracker_test.go b/x/crosschain/types/message_add_to_in_tx_tracker_test.go index 22d7ff08e9..c05272224f 100644 --- a/x/crosschain/types/message_add_to_in_tx_tracker_test.go +++ b/x/crosschain/types/message_add_to_in_tx_tracker_test.go @@ -5,7 +5,7 @@ import ( errorsmod "cosmossdk.io/errors" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/crosschain/types" @@ -52,10 +52,10 @@ func TestMsgAddToInTxTracker_ValidateBasic(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - assert.ErrorIs(t, err, tt.err) + require.ErrorIs(t, err, tt.err) return } - assert.NoError(t, err) + require.NoError(t, err) }) } } diff --git a/x/crosschain/types/message_add_to_out_tx_tracker_test.go b/x/crosschain/types/message_add_to_out_tx_tracker_test.go index 8caa666b53..8a06041989 100644 --- a/x/crosschain/types/message_add_to_out_tx_tracker_test.go +++ b/x/crosschain/types/message_add_to_out_tx_tracker_test.go @@ -4,7 +4,7 @@ import ( "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/crosschain/types" ) @@ -32,10 +32,10 @@ func TestMsgAddToWatchList_ValidateBasic(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - assert.ErrorIs(t, err, tt.err) + require.ErrorIs(t, err, tt.err) return } - assert.NoError(t, err) + require.NoError(t, err) }) } } diff --git a/x/crosschain/types/message_migrate_tss_funds_test.go b/x/crosschain/types/message_migrate_tss_funds_test.go index 1bc7389651..a03a4e9ef4 100644 --- a/x/crosschain/types/message_migrate_tss_funds_test.go +++ b/x/crosschain/types/message_migrate_tss_funds_test.go @@ -4,7 +4,7 @@ import ( "testing" sdkmath "cosmossdk.io/math" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/x/crosschain/types" @@ -49,10 +49,10 @@ func TestNewMsgMigrateTssFunds(t *testing.T) { keeper.SetConfig(false) err := tt.msg.ValidateBasic() if tt.error { - assert.Error(t, err) + require.Error(t, err) return } else { - assert.NoError(t, err) + require.NoError(t, err) } }) } diff --git a/x/crosschain/types/message_update_tss_address_test.go b/x/crosschain/types/message_update_tss_address_test.go index ede82f094c..ae2bcb25a4 100644 --- a/x/crosschain/types/message_update_tss_address_test.go +++ b/x/crosschain/types/message_update_tss_address_test.go @@ -3,7 +3,7 @@ package types_test import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/testutil/keeper" crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types" ) @@ -45,10 +45,10 @@ func TestMessageUpdateTssAddress_ValidateBasic(t *testing.T) { keeper.SetConfig(false) err := tt.msg.ValidateBasic() if tt.error { - assert.Error(t, err) + require.Error(t, err) return } else { - assert.NoError(t, err) + require.NoError(t, err) } }) } diff --git a/x/crosschain/types/message_vote_on_observed_inbound_tx_test.go b/x/crosschain/types/message_vote_on_observed_inbound_tx_test.go index 29704a9101..777fb6f244 100644 --- a/x/crosschain/types/message_vote_on_observed_inbound_tx_test.go +++ b/x/crosschain/types/message_vote_on_observed_inbound_tx_test.go @@ -7,7 +7,7 @@ import ( "cosmossdk.io/math" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/crosschain/types" @@ -125,10 +125,10 @@ func TestMsgVoteOnObservedInboundTx_ValidateBasic(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - assert.ErrorIs(t, err, tt.err) + require.ErrorIs(t, err, tt.err) return } - assert.NoError(t, err) + require.NoError(t, err) }) } } @@ -153,89 +153,89 @@ func TestMsgVoteOnObservedInboundTx_Digest(t *testing.T) { EventIndex: 42, } hash := msg.Digest() - assert.NotEmpty(t, hash, "hash should not be empty") + require.NotEmpty(t, hash, "hash should not be empty") // creator not used msg2 := msg msg2.Creator = sample.AccAddress() hash2 := msg2.Digest() - assert.Equal(t, hash, hash2, "creator should not change hash") + require.Equal(t, hash, hash2, "creator should not change hash") // in block height not used msg2 = msg msg2.InBlockHeight = 43 hash2 = msg2.Digest() - assert.Equal(t, hash, hash2, "in block height should not change hash") + require.Equal(t, hash, hash2, "in block height should not change hash") // sender used msg2 = msg msg2.Sender = sample.AccAddress() hash2 = msg2.Digest() - assert.NotEqual(t, hash, hash2, "sender should change hash") + require.NotEqual(t, hash, hash2, "sender should change hash") // sender chain ID used msg2 = msg msg2.SenderChainId = 43 hash2 = msg2.Digest() - assert.NotEqual(t, hash, hash2, "sender chain ID should change hash") + require.NotEqual(t, hash, hash2, "sender chain ID should change hash") // tx origin used msg2 = msg msg2.TxOrigin = sample.StringRandom(r, 32) hash2 = msg2.Digest() - assert.NotEqual(t, hash, hash2, "tx origin should change hash") + require.NotEqual(t, hash, hash2, "tx origin should change hash") // receiver used msg2 = msg msg2.Receiver = sample.StringRandom(r, 32) hash2 = msg2.Digest() - assert.NotEqual(t, hash, hash2, "receiver should change hash") + require.NotEqual(t, hash, hash2, "receiver should change hash") // receiver chain ID used msg2 = msg msg2.ReceiverChain = 43 hash2 = msg2.Digest() - assert.NotEqual(t, hash, hash2, "receiver chain ID should change hash") + require.NotEqual(t, hash, hash2, "receiver chain ID should change hash") // amount used msg2 = msg msg2.Amount = math.NewUint(43) hash2 = msg2.Digest() - assert.NotEqual(t, hash, hash2, "amount should change hash") + require.NotEqual(t, hash, hash2, "amount should change hash") // message used msg2 = msg msg2.Message = sample.StringRandom(r, 32) hash2 = msg2.Digest() - assert.NotEqual(t, hash, hash2, "message should change hash") + require.NotEqual(t, hash, hash2, "message should change hash") // in tx hash used msg2 = msg msg2.InTxHash = sample.StringRandom(r, 32) hash2 = msg2.Digest() - assert.NotEqual(t, hash, hash2, "in tx hash should change hash") + require.NotEqual(t, hash, hash2, "in tx hash should change hash") // gas limit used msg2 = msg msg2.GasLimit = 43 hash2 = msg2.Digest() - assert.NotEqual(t, hash, hash2, "gas limit should change hash") + require.NotEqual(t, hash, hash2, "gas limit should change hash") // coin type used msg2 = msg msg2.CoinType = common.CoinType_ERC20 hash2 = msg2.Digest() - assert.NotEqual(t, hash, hash2, "coin type should change hash") + require.NotEqual(t, hash, hash2, "coin type should change hash") // asset used msg2 = msg msg2.Asset = sample.StringRandom(r, 32) hash2 = msg2.Digest() - assert.NotEqual(t, hash, hash2, "asset should change hash") + require.NotEqual(t, hash, hash2, "asset should change hash") // event index used msg2 = msg msg2.EventIndex = 43 hash2 = msg2.Digest() - assert.NotEqual(t, hash, hash2, "event index should change hash") + require.NotEqual(t, hash, hash2, "event index should change hash") } diff --git a/x/crosschain/types/message_vote_on_observed_outbound_tx_test.go b/x/crosschain/types/message_vote_on_observed_outbound_tx_test.go index fda1a04d1d..cce6a29c3c 100644 --- a/x/crosschain/types/message_vote_on_observed_outbound_tx_test.go +++ b/x/crosschain/types/message_vote_on_observed_outbound_tx_test.go @@ -6,7 +6,7 @@ import ( "cosmossdk.io/math" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/crosschain/types" @@ -91,10 +91,10 @@ func TestMsgVoteOnObservedOutboundTx_ValidateBasic(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - assert.ErrorIs(t, err, tt.err) + require.ErrorIs(t, err, tt.err) return } - assert.NoError(t, err) + require.NoError(t, err) }) } } @@ -117,77 +117,77 @@ func TestMsgVoteOnObservedOutboundTx_Digest(t *testing.T) { CoinType: common.CoinType_Zeta, } hash := msg.Digest() - assert.NotEmpty(t, hash, "hash should not be empty") + require.NotEmpty(t, hash, "hash should not be empty") // creator not used msg2 := msg msg2.Creator = sample.AccAddress() hash2 := msg2.Digest() - assert.Equal(t, hash, hash2, "creator should not change hash") + require.Equal(t, hash, hash2, "creator should not change hash") // status not used msg2 = msg msg2.Status = common.ReceiveStatus_Failed hash2 = msg2.Digest() - assert.Equal(t, hash, hash2, "status should not change hash") + require.Equal(t, hash, hash2, "status should not change hash") // cctx hash used msg2 = msg msg2.CctxHash = sample.StringRandom(r, 32) hash2 = msg2.Digest() - assert.NotEqual(t, hash, hash2, "cctx hash should change hash") + require.NotEqual(t, hash, hash2, "cctx hash should change hash") // observed outbound tx hash used msg2 = msg msg2.ObservedOutTxHash = sample.StringRandom(r, 32) hash2 = msg2.Digest() - assert.NotEqual(t, hash, hash2, "observed outbound tx hash should change hash") + require.NotEqual(t, hash, hash2, "observed outbound tx hash should change hash") // observed outbound tx block height used msg2 = msg msg2.ObservedOutTxBlockHeight = 43 hash2 = msg2.Digest() - assert.NotEqual(t, hash, hash2, "observed outbound tx block height should change hash") + require.NotEqual(t, hash, hash2, "observed outbound tx block height should change hash") // observed outbound tx gas used used msg2 = msg msg2.ObservedOutTxGasUsed = 43 hash2 = msg2.Digest() - assert.NotEqual(t, hash, hash2, "observed outbound tx gas used should change hash") + require.NotEqual(t, hash, hash2, "observed outbound tx gas used should change hash") // observed outbound tx effective gas price used msg2 = msg msg2.ObservedOutTxEffectiveGasPrice = math.NewInt(43) hash2 = msg2.Digest() - assert.NotEqual(t, hash, hash2, "observed outbound tx effective gas price should change hash") + require.NotEqual(t, hash, hash2, "observed outbound tx effective gas price should change hash") // observed outbound tx effective gas limit used msg2 = msg msg2.ObservedOutTxEffectiveGasLimit = 43 hash2 = msg2.Digest() - assert.NotEqual(t, hash, hash2, "observed outbound tx effective gas limit should change hash") + require.NotEqual(t, hash, hash2, "observed outbound tx effective gas limit should change hash") // zeta minted used msg2 = msg msg2.ValueReceived = math.NewUint(43) hash2 = msg2.Digest() - assert.NotEqual(t, hash, hash2, "zeta minted should change hash") + require.NotEqual(t, hash, hash2, "zeta minted should change hash") // out tx chain used msg2 = msg msg2.OutTxChain = 43 hash2 = msg2.Digest() - assert.NotEqual(t, hash, hash2, "out tx chain should change hash") + require.NotEqual(t, hash, hash2, "out tx chain should change hash") // out tx tss nonce used msg2 = msg msg2.OutTxTssNonce = 43 hash2 = msg2.Digest() - assert.NotEqual(t, hash, hash2, "out tx tss nonce should change hash") + require.NotEqual(t, hash, hash2, "out tx tss nonce should change hash") // coin type used msg2 = msg msg2.CoinType = common.CoinType_ERC20 hash2 = msg2.Digest() - assert.NotEqual(t, hash, hash2, "coin type should change hash") + require.NotEqual(t, hash, hash2, "coin type should change hash") } diff --git a/x/emissions/abci_test.go b/x/emissions/abci_test.go index 50651ca3e2..28ca327d50 100644 --- a/x/emissions/abci_test.go +++ b/x/emissions/abci_test.go @@ -142,27 +142,27 @@ package emissions_test // t.Run(tt.name, func(t *testing.T) { // app, ctx, _, minter := SetupApp(t, tt.params, getaZetaFromString(tt.startingEmissionPool)) // err := app.BankKeeper.SendCoinsFromAccountToModule(ctx, minter.GetAddress(), emissionsModuleTypes.ModuleName, getaZetaFromString(tt.startingEmissionPool)) -// assert.NoError(t, err) +// require.NoError(t, err) // GenerateTestDataMaths(app, ctx, tt.testMaxHeight, tt.inputFilename) // defer func(t *testing.T, fp string) { // err := os.RemoveAll(fp) -// assert.NoError(t, err) +// require.NoError(t, err) // }(t, tt.inputFilename) // // if tt.generateOnly { // return // } // inputTestData, err := GetInputData(tt.inputFilename) -// assert.NoError(t, err) +// require.NoError(t, err) // sort.SliceStable(inputTestData, func(i, j int) bool { return inputTestData[i].BlockHeight < inputTestData[j].BlockHeight }) // startHeight := ctx.BlockHeight() -// assert.Equal(t, startHeight, inputTestData[0].BlockHeight, "starting block height should be equal to the first block height in the input data") +// require.Equal(t, startHeight, inputTestData[0].BlockHeight, "starting block height should be equal to the first block height in the input data") // for i := startHeight; i < tt.testMaxHeight; i++ { // //The First distribution will occur only when begin-block is triggered // reservesFactor, bondFactor, durationFactor := app.EmissionsKeeper.GetBlockRewardComponents(ctx) -// assert.Equal(t, inputTestData[i-1].ReservesFactor, reservesFactor, "reserves factor should be equal to the input data"+fmt.Sprintf(" , block height: %d", i)) -// assert.Equal(t, inputTestData[i-1].BondFactor, bondFactor, "bond factor should be equal to the input data"+fmt.Sprintf(" , block height: %d", i)) -// assert.Equal(t, inputTestData[i-1].DurationFactor, durationFactor.String(), "duration factor should be equal to the input data"+fmt.Sprintf(" , block height: %d", i)) +// require.Equal(t, inputTestData[i-1].ReservesFactor, reservesFactor, "reserves factor should be equal to the input data"+fmt.Sprintf(" , block height: %d", i)) +// require.Equal(t, inputTestData[i-1].BondFactor, bondFactor, "bond factor should be equal to the input data"+fmt.Sprintf(" , block height: %d", i)) +// require.Equal(t, inputTestData[i-1].DurationFactor, durationFactor.String(), "duration factor should be equal to the input data"+fmt.Sprintf(" , block height: %d", i)) // emissionsModule.BeginBlocker(ctx, app.EmissionsKeeper) // ctx = ctx.WithBlockHeight(i + 1) // } diff --git a/x/emissions/genesis_test.go b/x/emissions/genesis_test.go index 7ad8ec6aa6..cae3948ce1 100644 --- a/x/emissions/genesis_test.go +++ b/x/emissions/genesis_test.go @@ -3,7 +3,7 @@ package emissions_test import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/nullify" "github.com/zeta-chain/zetacore/testutil/sample" @@ -25,10 +25,10 @@ func TestGenesis(t *testing.T) { k, ctx := keepertest.EmissionsKeeper(t) emissions.InitGenesis(ctx, *k, genesisState) got := emissions.ExportGenesis(ctx, *k) - assert.NotNil(t, got) + require.NotNil(t, got) // Compare genesis after init and export nullify.Fill(&genesisState) nullify.Fill(got) - assert.Equal(t, genesisState, *got) + require.Equal(t, genesisState, *got) } diff --git a/x/emissions/keeper/block_rewards_components_test.go b/x/emissions/keeper/block_rewards_components_test.go index f8d206fbde..29acc7b07b 100644 --- a/x/emissions/keeper/block_rewards_components_test.go +++ b/x/emissions/keeper/block_rewards_components_test.go @@ -4,7 +4,7 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" emissionskeeper "github.com/zeta-chain/zetacore/x/emissions/keeper" ) @@ -43,8 +43,8 @@ func TestKeeper_CalculateFixedValidatorRewards(t *testing.T) { for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { blockRewards, err := emissionskeeper.CalculateFixedValidatorRewards(tc.blockTimeInSecs) - assert.NoError(t, err) - assert.Equal(t, tc.expectedBlockRewards, blockRewards) + require.NoError(t, err) + require.Equal(t, tc.expectedBlockRewards, blockRewards) }) } } diff --git a/x/emissions/keeper/params_test.go b/x/emissions/keeper/params_test.go index 159e948a55..128d9ced3e 100644 --- a/x/emissions/keeper/params_test.go +++ b/x/emissions/keeper/params_test.go @@ -4,7 +4,7 @@ import ( "testing" sdkmath "cosmossdk.io/math" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" emissionstypes "github.com/zeta-chain/zetacore/x/emissions/types" ) @@ -235,9 +235,9 @@ func TestKeeper_GetParams(t *testing.T) { }, tt.isPanic) if tt.isPanic != "" { - assert.Equal(t, defaultParams, k.GetParams(ctx)) + require.Equal(t, defaultParams, k.GetParams(ctx)) } else { - assert.Equal(t, tt.params, k.GetParams(ctx)) + require.Equal(t, tt.params, k.GetParams(ctx)) } }) } @@ -247,7 +247,7 @@ func assertPanic(t *testing.T, f func(), errorLog string) { defer func() { r := recover() if r != nil { - assert.Contains(t, r, errorLog) + require.Contains(t, r, errorLog) } }() f() diff --git a/x/emissions/types/genesis_test.go b/x/emissions/types/genesis_test.go index 46853a4e94..6e0f27b4bc 100644 --- a/x/emissions/types/genesis_test.go +++ b/x/emissions/types/genesis_test.go @@ -3,7 +3,7 @@ package types_test import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/x/emissions/types" ) @@ -27,9 +27,9 @@ func TestGenesisState_Validate(t *testing.T) { t.Run(tc.desc, func(t *testing.T) { err := tc.genState.Validate() if tc.valid { - assert.NoError(t, err) + require.NoError(t, err) } else { - assert.Error(t, err) + require.Error(t, err) } }) } diff --git a/x/fungible/client/cli/query_foreign_coins_test.go b/x/fungible/client/cli/query_foreign_coins_test.go index e661ee62c7..b2e2602f7c 100644 --- a/x/fungible/client/cli/query_foreign_coins_test.go +++ b/x/fungible/client/cli/query_foreign_coins_test.go @@ -8,7 +8,7 @@ package cli_test // // "github.com/cosmos/cosmos-sdk/client/flags" // clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli" -// "github.com/stretchr/testify/assert" +// "github.com/stretchr/testify/require" // tmcli "github.com/tendermint/tendermint/libs/cli" // "google.golang.org/grpc/codes" // "google.golang.org/grpc/status" @@ -26,7 +26,7 @@ package cli_test // t.Helper() // cfg := network.DefaultConfig() // state := types.GenesisState{} -// assert.NoError(t, cfg.Codec.UnmarshalJSON(cfg.GenesisState[types.ModuleName], &state)) +// require.NoError(t, cfg.Codec.UnmarshalJSON(cfg.GenesisState[types.ModuleName], &state)) // // for i := 0; i < n; i++ { // foreignCoins := types.ForeignCoins{ @@ -36,7 +36,7 @@ package cli_test // state.ForeignCoinsList = append(state.ForeignCoinsList, foreignCoins) // } // buf, err := cfg.Codec.MarshalJSON(&state) -// assert.NoError(t, err) +// require.NoError(t, err) // cfg.GenesisState[types.ModuleName] = buf // return network.New(t, cfg), state.ForeignCoinsList //} @@ -79,14 +79,14 @@ package cli_test // out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdShowForeignCoins(), args) // if tc.err != nil { // stat, ok := status.FromError(tc.err) -// assert.True(t, ok) -// assert.ErrorIs(t, stat.Err(), tc.err) +// require.True(t, ok) +// require.ErrorIs(t, stat.Err(), tc.err) // } else { -// assert.NoError(t, err) +// require.NoError(t, err) // var resp types.QueryGetForeignCoinsResponse -// assert.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) -// assert.NotNil(t, resp.ForeignCoins) -// assert.Equal(t, +// require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) +// require.NotNil(t, resp.ForeignCoins) +// require.Equal(t, // nullify.Fill(&tc.obj), // nullify.Fill(&resp.ForeignCoins), // ) @@ -119,11 +119,11 @@ package cli_test // for i := 0; i < len(objs); i += step { // args := request(nil, uint64(i), uint64(step), false) // out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdListForeignCoins(), args) -// assert.NoError(t, err) +// require.NoError(t, err) // var resp types.QueryAllForeignCoinsResponse -// assert.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) -// assert.LessOrEqual(t, len(resp.ForeignCoins), step) -// assert.Subset(t, +// require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) +// require.LessOrEqual(t, len(resp.ForeignCoins), step) +// require.Subset(t, // nullify.Fill(objs), // nullify.Fill(resp.ForeignCoins), // ) @@ -135,11 +135,11 @@ package cli_test // for i := 0; i < len(objs); i += step { // args := request(next, 0, uint64(step), false) // out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdListForeignCoins(), args) -// assert.NoError(t, err) +// require.NoError(t, err) // var resp types.QueryAllForeignCoinsResponse -// assert.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) -// assert.LessOrEqual(t, len(resp.ForeignCoins), step) -// assert.Subset(t, +// require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) +// require.LessOrEqual(t, len(resp.ForeignCoins), step) +// require.Subset(t, // nullify.Fill(objs), // nullify.Fill(resp.ForeignCoins), // ) @@ -149,12 +149,12 @@ package cli_test // t.Run("Total", func(t *testing.T) { // args := request(nil, 0, uint64(len(objs)), true) // out, err := clitestutil.ExecTestCLICmd(ctx, cli.CmdListForeignCoins(), args) -// assert.NoError(t, err) +// require.NoError(t, err) // var resp types.QueryAllForeignCoinsResponse -// assert.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) -// assert.NoError(t, err) -// assert.Equal(t, len(objs), int(resp.Pagination.Total)) -// assert.ElementsMatch(t, +// require.NoError(t, net.Config.Codec.UnmarshalJSON(out.Bytes(), &resp)) +// require.NoError(t, err) +// require.Equal(t, len(objs), int(resp.Pagination.Total)) +// require.ElementsMatch(t, // nullify.Fill(objs), // nullify.Fill(resp.ForeignCoins), // ) diff --git a/x/fungible/genesis_test.go b/x/fungible/genesis_test.go index 2b72fb443f..119e862a18 100644 --- a/x/fungible/genesis_test.go +++ b/x/fungible/genesis_test.go @@ -3,7 +3,7 @@ package fungible_test import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/nullify" "github.com/zeta-chain/zetacore/testutil/sample" @@ -26,10 +26,10 @@ func TestGenesis(t *testing.T) { k, ctx, _, _ := keepertest.FungibleKeeper(t) fungible.InitGenesis(ctx, *k, genesisState) got := fungible.ExportGenesis(ctx, *k) - assert.NotNil(t, got) + require.NotNil(t, got) // Compare genesis after init and export nullify.Fill(&genesisState) nullify.Fill(got) - assert.Equal(t, genesisState, *got) + require.Equal(t, genesisState, *got) } diff --git a/x/fungible/keeper/deposits_test.go b/x/fungible/keeper/deposits_test.go index d352851be3..4131a1e00d 100644 --- a/x/fungible/keeper/deposits_test.go +++ b/x/fungible/keeper/deposits_test.go @@ -6,7 +6,7 @@ import ( "cosmossdk.io/math" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" "github.com/zeta-chain/zetacore/testutil/contracts" testkeeper "github.com/zeta-chain/zetacore/testutil/keeper" @@ -40,12 +40,12 @@ func TestKeeper_ZRC20DepositAndCallContract(t *testing.T) { common.CoinType_Gas, sample.EthAddress().String(), ) - assert.NoError(t, err) - assert.False(t, contractCall) + require.NoError(t, err) + require.False(t, contractCall) balance, err := k.BalanceOfZRC4(ctx, zrc20, to) - assert.NoError(t, err) - assert.Equal(t, big.NewInt(42), balance) + require.NoError(t, err) + require.Equal(t, big.NewInt(42), balance) }) t.Run("can deposit non-gas coin for transfers", func(t *testing.T) { @@ -72,12 +72,12 @@ func TestKeeper_ZRC20DepositAndCallContract(t *testing.T) { common.CoinType_ERC20, assetAddress, ) - assert.NoError(t, err) - assert.False(t, contractCall) + require.NoError(t, err) + require.False(t, contractCall) balance, err := k.BalanceOfZRC4(ctx, zrc20, to) - assert.NoError(t, err) - assert.Equal(t, big.NewInt(42), balance) + require.NoError(t, err) + require.Equal(t, big.NewInt(42), balance) }) t.Run("should fail if trying to call a contract with data to a EOC", func(t *testing.T) { @@ -104,7 +104,7 @@ func TestKeeper_ZRC20DepositAndCallContract(t *testing.T) { common.CoinType_ERC20, assetAddress, ) - assert.ErrorIs(t, err, types.ErrCallNonContract) + require.ErrorIs(t, err, types.ErrCallNonContract) }) t.Run("can deposit coin for transfers with liquidity cap not reached", func(t *testing.T) { @@ -121,17 +121,17 @@ func TestKeeper_ZRC20DepositAndCallContract(t *testing.T) { // there is an initial total supply minted during gas pool setup initialTotalSupply, err := k.TotalSupplyZRC4(ctx, zrc20) - assert.NoError(t, err) + require.NoError(t, err) // set a liquidity cap coin, found := k.GetForeignCoins(ctx, zrc20.String()) - assert.True(t, found) + require.True(t, found) coin.LiquidityCap = math.NewUint(initialTotalSupply.Uint64() + 1000) k.SetForeignCoins(ctx, coin) // increase total supply _, err = k.DepositZRC20(ctx, zrc20, sample.EthAddress(), big.NewInt(500)) - assert.NoError(t, err) + require.NoError(t, err) // deposit to := sample.EthAddress() @@ -145,12 +145,12 @@ func TestKeeper_ZRC20DepositAndCallContract(t *testing.T) { common.CoinType_Gas, sample.EthAddress().String(), ) - assert.NoError(t, err) - assert.False(t, contractCall) + require.NoError(t, err) + require.False(t, contractCall) balance, err := k.BalanceOfZRC4(ctx, zrc20, to) - assert.NoError(t, err) - assert.Equal(t, big.NewInt(500), balance) + require.NoError(t, err) + require.Equal(t, big.NewInt(500), balance) }) t.Run("should fail if coin paused", func(t *testing.T) { @@ -167,7 +167,7 @@ func TestKeeper_ZRC20DepositAndCallContract(t *testing.T) { // pause the coin coin, found := k.GetForeignCoins(ctx, zrc20.String()) - assert.True(t, found) + require.True(t, found) coin.Paused = true k.SetForeignCoins(ctx, coin) @@ -182,7 +182,7 @@ func TestKeeper_ZRC20DepositAndCallContract(t *testing.T) { common.CoinType_Gas, sample.EthAddress().String(), ) - assert.ErrorIs(t, err, types.ErrPausedZRC20) + require.ErrorIs(t, err, types.ErrPausedZRC20) }) t.Run("should fail if liquidity cap reached", func(t *testing.T) { @@ -199,17 +199,17 @@ func TestKeeper_ZRC20DepositAndCallContract(t *testing.T) { // there is an initial total supply minted during gas pool setup initialTotalSupply, err := k.TotalSupplyZRC4(ctx, zrc20) - assert.NoError(t, err) + require.NoError(t, err) // set a liquidity cap coin, found := k.GetForeignCoins(ctx, zrc20.String()) - assert.True(t, found) + require.True(t, found) coin.LiquidityCap = math.NewUint(initialTotalSupply.Uint64() + 1000) k.SetForeignCoins(ctx, coin) // increase total supply _, err = k.DepositZRC20(ctx, zrc20, sample.EthAddress(), big.NewInt(500)) - assert.NoError(t, err) + require.NoError(t, err) // deposit (500 + 501 > 1000) to := sample.EthAddress() @@ -223,7 +223,7 @@ func TestKeeper_ZRC20DepositAndCallContract(t *testing.T) { common.CoinType_Gas, sample.EthAddress().String(), ) - assert.ErrorIs(t, err, types.ErrForeignCoinCapReached) + require.ErrorIs(t, err, types.ErrForeignCoinCapReached) }) t.Run("should fail if gas coin not found", func(t *testing.T) { @@ -249,7 +249,7 @@ func TestKeeper_ZRC20DepositAndCallContract(t *testing.T) { common.CoinType_Gas, sample.EthAddress().String(), ) - assert.ErrorIs(t, err, crosschaintypes.ErrGasCoinNotFound) + require.ErrorIs(t, err, crosschaintypes.ErrGasCoinNotFound) }) t.Run("should fail if zrc20 not found", func(t *testing.T) { @@ -275,7 +275,7 @@ func TestKeeper_ZRC20DepositAndCallContract(t *testing.T) { common.CoinType_ERC20, assetAddress, ) - assert.ErrorIs(t, err, crosschaintypes.ErrForeignCoinNotFound) + require.ErrorIs(t, err, crosschaintypes.ErrForeignCoinNotFound) }) t.Run("should return contract call if receiver is a contract", func(t *testing.T) { @@ -291,7 +291,7 @@ func TestKeeper_ZRC20DepositAndCallContract(t *testing.T) { zrc20 := setupGasCoin(t, ctx, k, sdkk.EvmKeeper, chain.ChainId, "foobar", "foobar") example, err := k.DeployContract(ctx, contracts.ExampleMetaData) - assert.NoError(t, err) + require.NoError(t, err) assertContractDeployment(t, sdkk.EvmKeeper, ctx, example) // deposit @@ -305,12 +305,12 @@ func TestKeeper_ZRC20DepositAndCallContract(t *testing.T) { common.CoinType_Gas, sample.EthAddress().String(), ) - assert.NoError(t, err) - assert.True(t, contractCall) + require.NoError(t, err) + require.True(t, contractCall) balance, err := k.BalanceOfZRC4(ctx, zrc20, example) - assert.NoError(t, err) - assert.Equal(t, big.NewInt(42), balance) + require.NoError(t, err) + require.Equal(t, big.NewInt(42), balance) // check onCrossChainCall() hook was called assertExampleBarValue(t, ctx, k, example, 42) @@ -329,7 +329,7 @@ func TestKeeper_ZRC20DepositAndCallContract(t *testing.T) { zrc20 := setupGasCoin(t, ctx, k, sdkk.EvmKeeper, chain.ChainId, "foobar", "foobar") reverter, err := k.DeployContract(ctx, contracts.ReverterMetaData) - assert.NoError(t, err) + require.NoError(t, err) assertContractDeployment(t, sdkk.EvmKeeper, ctx, reverter) // deposit @@ -343,11 +343,11 @@ func TestKeeper_ZRC20DepositAndCallContract(t *testing.T) { common.CoinType_Gas, sample.EthAddress().String(), ) - assert.Error(t, err) - assert.True(t, contractCall) + require.Error(t, err) + require.True(t, contractCall) balance, err := k.BalanceOfZRC4(ctx, zrc20, reverter) - assert.NoError(t, err) - assert.EqualValues(t, int64(0), balance.Int64()) + require.NoError(t, err) + require.EqualValues(t, int64(0), balance.Int64()) }) } diff --git a/x/fungible/keeper/evm_hooks_test.go b/x/fungible/keeper/evm_hooks_test.go index ae77d2d202..696fbbd9cd 100644 --- a/x/fungible/keeper/evm_hooks_test.go +++ b/x/fungible/keeper/evm_hooks_test.go @@ -4,7 +4,7 @@ import ( "testing" ethtypes "github.com/ethereum/go-ethereum/core/types" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/fungible/types" @@ -99,13 +99,13 @@ func TestKeeper_CheckPausedZRC20(t *testing.T) { assertUnpaused := func(zrc20 string) { fc, found := k.GetForeignCoins(ctx, zrc20) - assert.True(t, found) - assert.False(t, fc.Paused) + require.True(t, found) + require.False(t, fc.Paused) } assertPaused := func(zrc20 string) { fc, found := k.GetForeignCoins(ctx, zrc20) - assert.True(t, found) - assert.True(t, fc.Paused) + require.True(t, found) + require.True(t, fc.Paused) } // setup ZRC20 @@ -125,9 +125,9 @@ func TestKeeper_CheckPausedZRC20(t *testing.T) { // process test err := k.CheckPausedZRC20(ctx, tc.receipt) if tc.wantErr { - assert.ErrorIs(t, err, types.ErrPausedZRC20) + require.ErrorIs(t, err, types.ErrPausedZRC20) } else { - assert.NoError(t, err) + require.NoError(t, err) } }) } diff --git a/x/fungible/keeper/evm_test.go b/x/fungible/keeper/evm_test.go index 877dc70c02..b6810a6998 100644 --- a/x/fungible/keeper/evm_test.go +++ b/x/fungible/keeper/evm_test.go @@ -10,8 +10,8 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" evmkeeper "github.com/evmos/ethermint/x/evm/keeper" evmtypes "github.com/evmos/ethermint/x/evm/types" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" "github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/systemcontract.sol" zetacommon "github.com/zeta-chain/zetacore/common" "github.com/zeta-chain/zetacore/server/config" @@ -26,19 +26,19 @@ import ( // get a valid chain id independently of the build flag func getValidChainID(t *testing.T) int64 { list := zetacommon.DefaultChainsList() - assert.NotEmpty(t, list) - assert.NotNil(t, list[0]) + require.NotEmpty(t, list) + require.NotNil(t, list[0]) return list[0].ChainId } -// assert that a contract has been deployed by checking stored code is non-empty. +// require that a contract has been deployed by checking stored code is non-empty. func assertContractDeployment(t *testing.T, k *evmkeeper.Keeper, ctx sdk.Context, contractAddress common.Address) { acc := k.GetAccount(ctx, contractAddress) - assert.NotNil(t, acc) + require.NotNil(t, acc) code := k.GetCode(ctx, common.BytesToHash(acc.CodeHash)) - assert.NotEmpty(t, code) + require.NotEmpty(t, code) } // deploySystemContracts deploys the system contracts and returns their addresses. @@ -51,28 +51,28 @@ func deploySystemContracts( var err error wzeta, err = k.DeployWZETA(ctx) - assert.NoError(t, err) - assert.NotEmpty(t, wzeta) + require.NoError(t, err) + require.NotEmpty(t, wzeta) assertContractDeployment(t, evmk, ctx, wzeta) uniswapV2Factory, err = k.DeployUniswapV2Factory(ctx) - assert.NoError(t, err) - assert.NotEmpty(t, uniswapV2Factory) + require.NoError(t, err) + require.NotEmpty(t, uniswapV2Factory) assertContractDeployment(t, evmk, ctx, uniswapV2Factory) uniswapV2Router, err = k.DeployUniswapV2Router02(ctx, uniswapV2Factory, wzeta) - assert.NoError(t, err) - assert.NotEmpty(t, uniswapV2Router) + require.NoError(t, err) + require.NotEmpty(t, uniswapV2Router) assertContractDeployment(t, evmk, ctx, uniswapV2Router) connector, err = k.DeployConnectorZEVM(ctx, wzeta) - assert.NoError(t, err) - assert.NotEmpty(t, connector) + require.NoError(t, err) + require.NotEmpty(t, connector) assertContractDeployment(t, evmk, ctx, connector) systemContract, err = k.DeploySystemContract(ctx, wzeta, uniswapV2Factory, uniswapV2Router) - assert.NoError(t, err) - assert.NotEmpty(t, systemContract) + require.NoError(t, err) + require.NotEmpty(t, systemContract) assertContractDeployment(t, evmk, ctx, systemContract) return @@ -87,7 +87,7 @@ func assertExampleBarValue( expected int64, ) { exampleABI, err := contracts.ExampleMetaData.GetAbi() - assert.NoError(t, err) + require.NoError(t, err) res, err := k.CallEVM( ctx, *exampleABI, @@ -100,11 +100,11 @@ func assertExampleBarValue( "bar", ) unpacked, err := exampleABI.Unpack("bar", res.Ret) - assert.NoError(t, err) - assert.NotZero(t, len(unpacked)) + require.NoError(t, err) + require.NotZero(t, len(unpacked)) bar, ok := unpacked[0].(*big.Int) - assert.True(t, ok) - assert.Equal(t, big.NewInt(expected), bar) + require.True(t, ok) + require.Equal(t, big.NewInt(expected), bar) } func TestKeeper_DeployZRC20Contract(t *testing.T) { @@ -125,42 +125,42 @@ func TestKeeper_DeployZRC20Contract(t *testing.T) { "foobar", big.NewInt(1000), ) - assert.NoError(t, err) + require.NoError(t, err) assertContractDeployment(t, sdkk.EvmKeeper, ctx, addr) // check foreign coin foreignCoins, found := k.GetForeignCoins(ctx, addr.Hex()) - assert.True(t, found) - assert.Equal(t, "foobar", foreignCoins.Asset) - assert.Equal(t, chainID, foreignCoins.ForeignChainId) - assert.Equal(t, uint32(8), foreignCoins.Decimals) - assert.Equal(t, "foo", foreignCoins.Name) - assert.Equal(t, "bar", foreignCoins.Symbol) - assert.Equal(t, zetacommon.CoinType_Gas, foreignCoins.CoinType) - assert.Equal(t, uint64(1000), foreignCoins.GasLimit) + require.True(t, found) + require.Equal(t, "foobar", foreignCoins.Asset) + require.Equal(t, chainID, foreignCoins.ForeignChainId) + require.Equal(t, uint32(8), foreignCoins.Decimals) + require.Equal(t, "foo", foreignCoins.Name) + require.Equal(t, "bar", foreignCoins.Symbol) + require.Equal(t, zetacommon.CoinType_Gas, foreignCoins.CoinType) + require.Equal(t, uint64(1000), foreignCoins.GasLimit) // can get the zrc20 data zrc20Data, err := k.QueryZRC20Data(ctx, addr) - assert.NoError(t, err) - assert.Equal(t, "foo", zrc20Data.Name) - assert.Equal(t, "bar", zrc20Data.Symbol) - assert.Equal(t, uint8(8), zrc20Data.Decimals) + require.NoError(t, err) + require.Equal(t, "foo", zrc20Data.Name) + require.Equal(t, "bar", zrc20Data.Symbol) + require.Equal(t, uint8(8), zrc20Data.Decimals) // can deposit tokens to := sample.EthAddress() oldBalance, err := k.BalanceOfZRC4(ctx, addr, to) - assert.NoError(t, err) - assert.NotNil(t, oldBalance) - assert.Equal(t, int64(0), oldBalance.Int64()) + require.NoError(t, err) + require.NotNil(t, oldBalance) + require.Equal(t, int64(0), oldBalance.Int64()) amount := big.NewInt(100) _, err = k.DepositZRC20(ctx, addr, to, amount) - assert.NoError(t, err) + require.NoError(t, err) newBalance, err := k.BalanceOfZRC4(ctx, addr, to) - assert.NoError(t, err) - assert.NotNil(t, newBalance) - assert.Equal(t, amount.Int64(), newBalance.Int64()) + require.NoError(t, err) + require.NotNil(t, newBalance) + require.Equal(t, amount.Int64(), newBalance.Int64()) }) } @@ -174,23 +174,23 @@ func TestKeeper_DeploySystemContract(t *testing.T) { // can find system contract address found, err := k.GetSystemContractAddress(ctx) - assert.NoError(t, err) - assert.Equal(t, systemContract, found) + require.NoError(t, err) + require.Equal(t, systemContract, found) // can find factory address found, err = k.GetUniswapV2FactoryAddress(ctx) - assert.NoError(t, err) - assert.Equal(t, uniswapV2Factory, found) + require.NoError(t, err) + require.Equal(t, uniswapV2Factory, found) // can find router address found, err = k.GetUniswapV2Router02Address(ctx) - assert.NoError(t, err) - assert.Equal(t, uniswapV2Router, found) + require.NoError(t, err) + require.Equal(t, uniswapV2Router, found) // can find the wzeta contract address found, err = k.GetWZetaContractAddress(ctx) - assert.NoError(t, err) - assert.Equal(t, wzeta, found) + require.NoError(t, err) + require.Equal(t, wzeta, found) }) t.Run("can deposit into wzeta", func(t *testing.T) { @@ -200,21 +200,21 @@ func TestKeeper_DeploySystemContract(t *testing.T) { wzeta, _, _, _, _ := deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) balance, err := k.BalanceOfZRC4(ctx, wzeta, types.ModuleAddressEVM) - assert.NoError(t, err) - assert.NotNil(t, balance) - assert.Equal(t, int64(0), balance.Int64()) + require.NoError(t, err) + require.NotNil(t, balance) + require.Equal(t, int64(0), balance.Int64()) amount := big.NewInt(100) err = sdkk.BankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins(sdk.NewCoin("azeta", sdk.NewIntFromBigInt(amount)))) - assert.NoError(t, err) + require.NoError(t, err) err = k.CallWZetaDeposit(ctx, types.ModuleAddressEVM, amount) - assert.NoError(t, err) + require.NoError(t, err) balance, err = k.BalanceOfZRC4(ctx, wzeta, types.ModuleAddressEVM) - assert.NoError(t, err) - assert.NotNil(t, balance) - assert.Equal(t, amount.Int64(), balance.Int64()) + require.NoError(t, err) + require.NotNil(t, balance) + require.Equal(t, amount.Int64(), balance.Int64()) }) } @@ -228,7 +228,7 @@ func TestKeeper_DepositZRC20AndCallContract(t *testing.T) { zrc20 := setupGasCoin(t, ctx, k, sdkk.EvmKeeper, chainID, "foobar", "FOOBAR") example, err := k.DeployContract(ctx, contracts.ExampleMetaData) - assert.NoError(t, err) + require.NoError(t, err) assertContractDeployment(t, sdkk.EvmKeeper, ctx, example) res, err := k.DepositZRC20AndCallContract( @@ -243,15 +243,15 @@ func TestKeeper_DepositZRC20AndCallContract(t *testing.T) { big.NewInt(42), []byte(""), ) - assert.NoError(t, err) - assert.False(t, types.IsContractReverted(res, err)) + require.NoError(t, err) + require.False(t, types.IsContractReverted(res, err)) balance, err := k.BalanceOfZRC4(ctx, zrc20, example) - assert.NoError(t, err) - assert.Equal(t, int64(42), balance.Int64()) + require.NoError(t, err) + require.Equal(t, int64(42), balance.Int64()) // check onCrossChainCall has been called exampleABI, err := contracts.ExampleMetaData.GetAbi() - assert.NoError(t, err) + require.NoError(t, err) res, err = k.CallEVM( ctx, *exampleABI, @@ -264,11 +264,11 @@ func TestKeeper_DepositZRC20AndCallContract(t *testing.T) { "bar", ) unpacked, err := exampleABI.Unpack("bar", res.Ret) - assert.NoError(t, err) - assert.NotZero(t, len(unpacked)) + require.NoError(t, err) + require.NotZero(t, len(unpacked)) bar, ok := unpacked[0].(*big.Int) - assert.True(t, ok) - assert.Equal(t, big.NewInt(42), bar) + require.True(t, ok) + require.Equal(t, big.NewInt(42), bar) }) t.Run("should return a revert error when the underlying contract call revert", func(t *testing.T) { @@ -281,7 +281,7 @@ func TestKeeper_DepositZRC20AndCallContract(t *testing.T) { // Deploy reverter reverter, err := k.DeployContract(ctx, contracts.ReverterMetaData) - assert.NoError(t, err) + require.NoError(t, err) assertContractDeployment(t, sdkk.EvmKeeper, ctx, reverter) res, err := k.DepositZRC20AndCallContract( @@ -296,10 +296,10 @@ func TestKeeper_DepositZRC20AndCallContract(t *testing.T) { big.NewInt(42), []byte(""), ) - assert.True(t, types.IsContractReverted(res, err)) + require.True(t, types.IsContractReverted(res, err)) balance, err := k.BalanceOfZRC4(ctx, zrc20, reverter) - assert.NoError(t, err) - assert.Zero(t, balance.Int64()) + require.NoError(t, err) + require.Zero(t, balance.Int64()) }) t.Run("should revert if the underlying contract doesn't exist", func(t *testing.T) { @@ -322,7 +322,7 @@ func TestKeeper_DepositZRC20AndCallContract(t *testing.T) { big.NewInt(42), []byte(""), ) - assert.True(t, types.IsContractReverted(res, err)) + require.True(t, types.IsContractReverted(res, err)) }) } @@ -333,10 +333,10 @@ func TestKeeper_CallEVMWithData(t *testing.T) { // Deploy example contract, err := k.DeployContract(ctx, contracts.ExampleMetaData) - assert.NoError(t, err) + require.NoError(t, err) assertContractDeployment(t, sdkk.EvmKeeper, ctx, contract) abi, err := contracts.ExampleMetaData.GetAbi() - assert.NoError(t, err) + require.NoError(t, err) // doRevert make contract reverted res, err := k.CallEVM( @@ -350,12 +350,12 @@ func TestKeeper_CallEVMWithData(t *testing.T) { false, "doRevert", ) - assert.Nil(t, res) - assert.True(t, types.IsContractReverted(res, err)) + require.Nil(t, res) + require.True(t, types.IsContractReverted(res, err)) // check reason is included for revert error // 0xbfb4ebcf is the hash of "Foo()" - assert.Contains(t, err.Error(), "reason: 0xbfb4ebcf") + require.Contains(t, err.Error(), "reason: 0xbfb4ebcf") res, err = k.CallEVM( ctx, @@ -368,8 +368,8 @@ func TestKeeper_CallEVMWithData(t *testing.T) { false, "doRevertWithMessage", ) - assert.Nil(t, res) - assert.True(t, types.IsContractReverted(res, err)) + require.Nil(t, res) + require.True(t, types.IsContractReverted(res, err)) res, err = k.CallEVM( ctx, @@ -382,8 +382,8 @@ func TestKeeper_CallEVMWithData(t *testing.T) { false, "doRevertWithRequire", ) - assert.Nil(t, res) - assert.True(t, types.IsContractReverted(res, err)) + require.Nil(t, res) + require.True(t, types.IsContractReverted(res, err)) // Not a revert error if another type of error res, err = k.CallEVM( @@ -397,10 +397,10 @@ func TestKeeper_CallEVMWithData(t *testing.T) { false, "doNotExist", ) - assert.Nil(t, res) - assert.Error(t, err) - assert.False(t, types.IsContractReverted(res, err)) - assert.NotContains(t, err.Error(), "reason:") + require.Nil(t, res) + require.Error(t, err) + require.False(t, types.IsContractReverted(res, err)) + require.NotContains(t, err.Error(), "reason:") // No revert with successfull call res, err = k.CallEVM( @@ -414,9 +414,9 @@ func TestKeeper_CallEVMWithData(t *testing.T) { false, "doSucceed", ) - assert.NotNil(t, res) - assert.NoError(t, err) - assert.False(t, types.IsContractReverted(res, err)) + require.NotNil(t, res) + require.NoError(t, err) + require.False(t, types.IsContractReverted(res, err)) }) t.Run("apply new message without gas limit estimates gas", func(t *testing.T) { @@ -473,8 +473,8 @@ func TestKeeper_CallEVMWithData(t *testing.T) { big.NewInt(100), nil, ) - assert.NoError(t, err) - assert.Equal(t, msgRes, res) + require.NoError(t, err) + require.Equal(t, msgRes, res) // Assert that the expected methods were called mockAuthKeeper.AssertExpectations(t) @@ -523,8 +523,8 @@ func TestKeeper_CallEVMWithData(t *testing.T) { big.NewInt(100), big.NewInt(1000), ) - assert.NoError(t, err) - assert.Equal(t, msgRes, res) + require.NoError(t, err) + require.Equal(t, msgRes, res) // Assert that the expected methods were called mockAuthKeeper.AssertExpectations(t) @@ -549,7 +549,7 @@ func TestKeeper_CallEVMWithData(t *testing.T) { big.NewInt(100), nil, ) - assert.ErrorIs(t, err, sample.ErrSample) + require.ErrorIs(t, err, sample.ErrSample) }) t.Run("EstimateGas failure returns error", func(t *testing.T) { @@ -585,7 +585,7 @@ func TestKeeper_CallEVMWithData(t *testing.T) { big.NewInt(100), nil, ) - assert.ErrorIs(t, err, sample.ErrSample) + require.ErrorIs(t, err, sample.ErrSample) }) t.Run("ApplyMessage failure returns error", func(t *testing.T) { @@ -639,6 +639,6 @@ func TestKeeper_CallEVMWithData(t *testing.T) { big.NewInt(100), nil, ) - assert.ErrorIs(t, err, sample.ErrSample) + require.ErrorIs(t, err, sample.ErrSample) }) } diff --git a/x/fungible/keeper/foreign_coins_test.go b/x/fungible/keeper/foreign_coins_test.go index c82f4d96be..0a5a0f37f0 100644 --- a/x/fungible/keeper/foreign_coins_test.go +++ b/x/fungible/keeper/foreign_coins_test.go @@ -4,7 +4,7 @@ import ( "strconv" "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -68,12 +68,12 @@ func TestKeeper_GetGasCoinForForeignCoin(t *testing.T) { ) fc, found := k.GetGasCoinForForeignCoin(ctx, 1) - assert.True(t, found) - assert.Equal(t, "bar", fc.Name) + require.True(t, found) + require.Equal(t, "bar", fc.Name) fc, found = k.GetGasCoinForForeignCoin(ctx, 2) - assert.False(t, found) + require.False(t, found) fc, found = k.GetGasCoinForForeignCoin(ctx, 3) - assert.False(t, found) + require.False(t, found) } func TestKeeperGetForeignCoinFromAsset(t *testing.T) { @@ -122,16 +122,16 @@ func TestKeeperGetForeignCoinFromAsset(t *testing.T) { ) fc, found := k.GetForeignCoinFromAsset(ctx, gasAsset, 1) - assert.True(t, found) - assert.Equal(t, "bar", fc.Name) + require.True(t, found) + require.Equal(t, "bar", fc.Name) fc, found = k.GetForeignCoinFromAsset(ctx, sample.EthAddress().String(), 1) - assert.False(t, found) + require.False(t, found) fc, found = k.GetForeignCoinFromAsset(ctx, "invalid_address", 1) - assert.False(t, found) + require.False(t, found) fc, found = k.GetForeignCoinFromAsset(ctx, gasAsset, 2) - assert.False(t, found) + require.False(t, found) fc, found = k.GetForeignCoinFromAsset(ctx, gasAsset, 3) - assert.False(t, found) + require.False(t, found) }) t.Run("can get foreign coin with non-checksum address", func(t *testing.T) { @@ -148,7 +148,7 @@ func TestKeeperGetForeignCoinFromAsset(t *testing.T) { ) fc, found := k.GetForeignCoinFromAsset(ctx, "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", 1) - assert.True(t, found) - assert.Equal(t, "foo", fc.Name) + require.True(t, found) + require.Equal(t, "foo", fc.Name) }) } diff --git a/x/fungible/keeper/gas_coin_and_pool_test.go b/x/fungible/keeper/gas_coin_and_pool_test.go index 196fc8a0fa..9bdd139fdc 100644 --- a/x/fungible/keeper/gas_coin_and_pool_test.go +++ b/x/fungible/keeper/gas_coin_and_pool_test.go @@ -7,7 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/common" evmkeeper "github.com/evmos/ethermint/x/evm/keeper" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" testkeeper "github.com/zeta-chain/zetacore/testutil/keeper" fungiblekeeper "github.com/zeta-chain/zetacore/x/fungible/keeper" @@ -32,7 +32,7 @@ func setupGasCoin( 8, nil, ) - assert.NoError(t, err) + require.NoError(t, err) assertContractDeployment(t, evmk, ctx, addr) return addr } @@ -57,7 +57,7 @@ func deployZRC20( assetAddress, big.NewInt(21_000), ) - assert.NoError(t, err) + require.NoError(t, err) assertContractDeployment(t, evmk, ctx, addr) return addr } @@ -76,7 +76,7 @@ func TestKeeper_SetupChainGasCoinAndPool(t *testing.T) { // can retrieve the gas coin found, err := k.QuerySystemContractGasCoinZRC20(ctx, big.NewInt(chainID)) - assert.NoError(t, err) - assert.Equal(t, zrc20, found) + require.NoError(t, err) + require.Equal(t, zrc20, found) }) } diff --git a/x/fungible/keeper/gas_price_test.go b/x/fungible/keeper/gas_price_test.go index d5295ed560..ec1bf267d8 100644 --- a/x/fungible/keeper/gas_price_test.go +++ b/x/fungible/keeper/gas_price_test.go @@ -5,7 +5,7 @@ import ( "testing" ethcommon "github.com/ethereum/go-ethereum/common" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/systemcontract.sol" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -21,19 +21,19 @@ func TestKeeper_SetGasPrice(t *testing.T) { queryGasPrice := func(chainID *big.Int) *big.Int { abi, err := systemcontract.SystemContractMetaData.GetAbi() - assert.NoError(t, err) + require.NoError(t, err) res, err := k.CallEVM(ctx, *abi, types.ModuleAddressEVM, system, keeper.BigIntZero, nil, false, false, "gasPriceByChainId", chainID) - assert.NoError(t, err) + require.NoError(t, err) unpacked, err := abi.Unpack("gasPriceByChainId", res.Ret) - assert.NoError(t, err) + require.NoError(t, err) gasPrice, ok := unpacked[0].(*big.Int) - assert.True(t, ok) + require.True(t, ok) return gasPrice } _, err := k.SetGasPrice(ctx, big.NewInt(1), big.NewInt(42)) - assert.NoError(t, err) - assert.Equal(t, big.NewInt(42), queryGasPrice(big.NewInt(1))) + require.NoError(t, err) + require.Equal(t, big.NewInt(42), queryGasPrice(big.NewInt(1))) } func TestKeeper_SetGasCoin(t *testing.T) { @@ -43,11 +43,11 @@ func TestKeeper_SetGasCoin(t *testing.T) { deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) err := k.SetGasCoin(ctx, big.NewInt(1), gas) - assert.NoError(t, err) + require.NoError(t, err) found, err := k.QuerySystemContractGasCoinZRC20(ctx, big.NewInt(1)) - assert.NoError(t, err) - assert.Equal(t, gas.Hex(), found.Hex()) + require.NoError(t, err) + require.Equal(t, gas.Hex(), found.Hex()) } func TestKeeper_SetGasZetaPool(t *testing.T) { @@ -59,17 +59,17 @@ func TestKeeper_SetGasZetaPool(t *testing.T) { queryZetaPool := func(chainID *big.Int) ethcommon.Address { abi, err := systemcontract.SystemContractMetaData.GetAbi() - assert.NoError(t, err) + require.NoError(t, err) res, err := k.CallEVM(ctx, *abi, types.ModuleAddressEVM, system, keeper.BigIntZero, nil, false, false, "gasZetaPoolByChainId", chainID) - assert.NoError(t, err) + require.NoError(t, err) unpacked, err := abi.Unpack("gasZetaPoolByChainId", res.Ret) - assert.NoError(t, err) + require.NoError(t, err) pool, ok := unpacked[0].(ethcommon.Address) - assert.True(t, ok) + require.True(t, ok) return pool } err := k.SetGasZetaPool(ctx, big.NewInt(1), zrc20) - assert.NoError(t, err) - assert.NotEqual(t, ethcommon.Address{}, queryZetaPool(big.NewInt(1))) + require.NoError(t, err) + require.NotEqual(t, ethcommon.Address{}, queryZetaPool(big.NewInt(1))) } diff --git a/x/fungible/keeper/gas_stability_pool_test.go b/x/fungible/keeper/gas_stability_pool_test.go index c2fb629267..1c9bbc7b12 100644 --- a/x/fungible/keeper/gas_stability_pool_test.go +++ b/x/fungible/keeper/gas_stability_pool_test.go @@ -4,7 +4,7 @@ import ( "math/big" "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" testkeeper "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/x/fungible/types" ) @@ -15,21 +15,21 @@ func TestKeeper_EnsureGasStabilityPoolAccountCreated(t *testing.T) { // account doesn't exist acc := k.GetAuthKeeper().GetAccount(ctx, types.GasStabilityPoolAddress()) - assert.Nil(t, acc) + require.Nil(t, acc) // create the account k.EnsureGasStabilityPoolAccountCreated(ctx) acc = k.GetAuthKeeper().GetAccount(ctx, types.GasStabilityPoolAddress()) - assert.NotNil(t, acc) - assert.Equal(t, types.GasStabilityPoolAddress(), acc.GetAddress()) + require.NotNil(t, acc) + require.Equal(t, types.GasStabilityPoolAddress(), acc.GetAddress()) // can call the method again without side effects k.EnsureGasStabilityPoolAccountCreated(ctx) acc2 := k.GetAuthKeeper().GetAccount(ctx, types.GasStabilityPoolAddress()) - assert.NotNil(t, acc2) - assert.True(t, acc.GetAddress().Equals(acc2.GetAddress())) - assert.Equal(t, acc.GetAccountNumber(), acc2.GetAccountNumber()) - assert.Equal(t, acc.GetSequence(), acc2.GetSequence()) + require.NotNil(t, acc2) + require.True(t, acc.GetAddress().Equals(acc2.GetAddress())) + require.Equal(t, acc.GetAccountNumber(), acc2.GetAccountNumber()) + require.Equal(t, acc.GetSequence(), acc2.GetSequence()) }) } @@ -46,25 +46,25 @@ func TestKeeper_FundGasStabilityPool(t *testing.T) { // balance is initially 0 balance, err := k.GetGasStabilityPoolBalance(ctx, chainID) - assert.NoError(t, err) - assert.Equal(t, int64(0), balance.Int64()) + require.NoError(t, err) + require.Equal(t, int64(0), balance.Int64()) // fund the gas stability pool err = k.FundGasStabilityPool(ctx, chainID, big.NewInt(100)) - assert.NoError(t, err) + require.NoError(t, err) // balance is now 100 balance, err = k.GetGasStabilityPoolBalance(ctx, chainID) - assert.NoError(t, err) - assert.Equal(t, int64(100), balance.Int64()) + require.NoError(t, err) + require.Equal(t, int64(100), balance.Int64()) // withdraw from the gas stability pool err = k.WithdrawFromGasStabilityPool(ctx, chainID, big.NewInt(50)) - assert.NoError(t, err) + require.NoError(t, err) // balance is now 50 balance, err = k.GetGasStabilityPoolBalance(ctx, chainID) - assert.NoError(t, err) - assert.Equal(t, int64(50), balance.Int64()) + require.NoError(t, err) + require.Equal(t, int64(50), balance.Int64()) }) } diff --git a/x/fungible/keeper/grpc_query_code_hash_test.go b/x/fungible/keeper/grpc_query_code_hash_test.go index 43d1010c90..e2359dc530 100644 --- a/x/fungible/keeper/grpc_query_code_hash_test.go +++ b/x/fungible/keeper/grpc_query_code_hash_test.go @@ -4,7 +4,7 @@ import ( "testing" ethcommon "github.com/ethereum/go-ethereum/common" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/fungible/types" @@ -17,14 +17,14 @@ func TestKeeper_CodeHash(t *testing.T) { wzeta, _, _, _, _ := deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) acc := sdkk.EvmKeeper.GetAccount(ctx, wzeta) - assert.NotNil(t, acc) - assert.NotNil(t, acc.CodeHash) + require.NotNil(t, acc) + require.NotNil(t, acc.CodeHash) res, err := k.CodeHash(ctx, &types.QueryCodeHashRequest{ Address: wzeta.Hex(), }) - assert.NoError(t, err) - assert.Equal(t, ethcommon.BytesToHash(acc.CodeHash).Hex(), res.CodeHash) + require.NoError(t, err) + require.Equal(t, ethcommon.BytesToHash(acc.CodeHash).Hex(), res.CodeHash) }) t.Run("should return error if address is invalid", func(t *testing.T) { @@ -33,8 +33,8 @@ func TestKeeper_CodeHash(t *testing.T) { _, err := k.CodeHash(ctx, &types.QueryCodeHashRequest{ Address: "invalid", }) - assert.Error(t, err) - assert.ErrorContains(t, err, "invalid address") + require.Error(t, err) + require.ErrorContains(t, err, "invalid address") }) t.Run("should return error if account not found", func(t *testing.T) { @@ -43,8 +43,8 @@ func TestKeeper_CodeHash(t *testing.T) { _, err := k.CodeHash(ctx, &types.QueryCodeHashRequest{ Address: sample.EthAddress().Hex(), }) - assert.Error(t, err) - assert.ErrorContains(t, err, "account not found") + require.Error(t, err) + require.ErrorContains(t, err, "account not found") }) t.Run("should return error if account is not a contract", func(t *testing.T) { @@ -54,7 +54,7 @@ func TestKeeper_CodeHash(t *testing.T) { _, err := k.CodeHash(ctx, &types.QueryCodeHashRequest{ Address: types.ModuleAddressEVM.Hex(), }) - assert.Error(t, err) - assert.ErrorContains(t, err, "account is not a contract") + require.Error(t, err) + require.ErrorContains(t, err, "account is not a contract") }) } diff --git a/x/fungible/keeper/grpc_query_foreign_coins_test.go b/x/fungible/keeper/grpc_query_foreign_coins_test.go index bb9f641364..76b4b2e7c0 100644 --- a/x/fungible/keeper/grpc_query_foreign_coins_test.go +++ b/x/fungible/keeper/grpc_query_foreign_coins_test.go @@ -6,7 +6,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -54,10 +54,10 @@ func TestForeignCoinsQuerySingle(t *testing.T) { t.Run(tc.desc, func(t *testing.T) { response, err := keeper.ForeignCoins(wctx, tc.request) if tc.err != nil { - assert.ErrorIs(t, err, tc.err) + require.ErrorIs(t, err, tc.err) } else { - assert.NoError(t, err) - assert.Equal(t, + require.NoError(t, err) + require.Equal(t, nullify.Fill(tc.response), nullify.Fill(response), ) @@ -85,9 +85,9 @@ func TestForeignCoinsQueryPaginated(t *testing.T) { step := 2 for i := 0; i < len(msgs); i += step { resp, err := keeper.ForeignCoinsAll(wctx, request(nil, uint64(i), uint64(step), false)) - assert.NoError(t, err) - assert.LessOrEqual(t, len(resp.ForeignCoins), step) - assert.Subset(t, + require.NoError(t, err) + require.LessOrEqual(t, len(resp.ForeignCoins), step) + require.Subset(t, nullify.Fill(msgs), nullify.Fill(resp.ForeignCoins), ) @@ -98,9 +98,9 @@ func TestForeignCoinsQueryPaginated(t *testing.T) { var next []byte for i := 0; i < len(msgs); i += step { resp, err := keeper.ForeignCoinsAll(wctx, request(next, 0, uint64(step), false)) - assert.NoError(t, err) - assert.LessOrEqual(t, len(resp.ForeignCoins), step) - assert.Subset(t, + require.NoError(t, err) + require.LessOrEqual(t, len(resp.ForeignCoins), step) + require.Subset(t, nullify.Fill(msgs), nullify.Fill(resp.ForeignCoins), ) @@ -109,15 +109,15 @@ func TestForeignCoinsQueryPaginated(t *testing.T) { }) t.Run("Total", func(t *testing.T) { resp, err := keeper.ForeignCoinsAll(wctx, request(nil, 0, 0, true)) - assert.NoError(t, err) - assert.Equal(t, len(msgs), int(resp.Pagination.Total)) - assert.ElementsMatch(t, + require.NoError(t, err) + require.Equal(t, len(msgs), int(resp.Pagination.Total)) + require.ElementsMatch(t, nullify.Fill(msgs), nullify.Fill(resp.ForeignCoins), ) }) t.Run("InvalidRequest", func(t *testing.T) { _, err := keeper.ForeignCoinsAll(wctx, nil) - assert.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) + require.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) }) } diff --git a/x/fungible/keeper/grpc_query_params_test.go b/x/fungible/keeper/grpc_query_params_test.go index 377fe3f664..634c6a38f6 100644 --- a/x/fungible/keeper/grpc_query_params_test.go +++ b/x/fungible/keeper/grpc_query_params_test.go @@ -4,7 +4,7 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" testkeeper "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/x/fungible/types" ) @@ -16,6 +16,6 @@ func TestParamsQuery(t *testing.T) { keeper.SetParams(ctx, params) response, err := keeper.Params(wctx, &types.QueryParamsRequest{}) - assert.NoError(t, err) - assert.Equal(t, &types.QueryParamsResponse{Params: params}, response) + require.NoError(t, err) + require.Equal(t, &types.QueryParamsResponse{Params: params}, response) } diff --git a/x/fungible/keeper/msg_server_deploy_fungible_coin_zrc20_test.go b/x/fungible/keeper/msg_server_deploy_fungible_coin_zrc20_test.go index b31725f422..1e64419f1a 100644 --- a/x/fungible/keeper/msg_server_deploy_fungible_coin_zrc20_test.go +++ b/x/fungible/keeper/msg_server_deploy_fungible_coin_zrc20_test.go @@ -6,7 +6,7 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ethcommon "github.com/ethereum/go-ethereum/common" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -36,24 +36,24 @@ func TestMsgServer_DeployFungibleCoinZRC20(t *testing.T) { common.CoinType_Gas, 1000000, )) - assert.NoError(t, err) + require.NoError(t, err) gasAddress := res.Address assertContractDeployment(t, sdkk.EvmKeeper, ctx, ethcommon.HexToAddress(gasAddress)) // can retrieve the gas coin foreignCoin, found := k.GetForeignCoins(ctx, gasAddress) - assert.True(t, found) - assert.Equal(t, foreignCoin.CoinType, common.CoinType_Gas) - assert.Contains(t, foreignCoin.Name, "foo") + require.True(t, found) + require.Equal(t, foreignCoin.CoinType, common.CoinType_Gas) + require.Contains(t, foreignCoin.Name, "foo") // check gas limit gasLimit, err := k.QueryGasLimit(ctx, ethcommon.HexToAddress(foreignCoin.Zrc20ContractAddress)) - assert.NoError(t, err) - assert.Equal(t, uint64(1000000), gasLimit.Uint64()) + require.NoError(t, err) + require.Equal(t, uint64(1000000), gasLimit.Uint64()) gas, err := k.QuerySystemContractGasCoinZRC20(ctx, big.NewInt(chainID)) - assert.NoError(t, err) - assert.Equal(t, gasAddress, gas.Hex()) + require.NoError(t, err) + require.Equal(t, gasAddress, gas.Hex()) // can deploy non-gas zrc20 res, err = msgServer.DeployFungibleCoinZRC20(ctx, types.NewMsgDeployFungibleCoinZRC20( @@ -66,24 +66,24 @@ func TestMsgServer_DeployFungibleCoinZRC20(t *testing.T) { common.CoinType_ERC20, 2000000, )) - assert.NoError(t, err) + require.NoError(t, err) assertContractDeployment(t, sdkk.EvmKeeper, ctx, ethcommon.HexToAddress(res.Address)) foreignCoin, found = k.GetForeignCoins(ctx, res.Address) - assert.True(t, found) - assert.Equal(t, foreignCoin.CoinType, common.CoinType_ERC20) - assert.Contains(t, foreignCoin.Name, "bar") + require.True(t, found) + require.Equal(t, foreignCoin.CoinType, common.CoinType_ERC20) + require.Contains(t, foreignCoin.Name, "bar") // check gas limit gasLimit, err = k.QueryGasLimit(ctx, ethcommon.HexToAddress(foreignCoin.Zrc20ContractAddress)) - assert.NoError(t, err) - assert.Equal(t, uint64(2000000), gasLimit.Uint64()) + require.NoError(t, err) + require.Equal(t, uint64(2000000), gasLimit.Uint64()) // gas should remain the same gas, err = k.QuerySystemContractGasCoinZRC20(ctx, big.NewInt(chainID)) - assert.NoError(t, err) - assert.NotEqual(t, res.Address, gas.Hex()) - assert.Equal(t, gasAddress, gas.Hex()) + require.NoError(t, err) + require.NotEqual(t, res.Address, gas.Hex()) + require.Equal(t, gasAddress, gas.Hex()) }) t.Run("should not deploy a new zrc20 if not admin", func(t *testing.T) { @@ -104,8 +104,8 @@ func TestMsgServer_DeployFungibleCoinZRC20(t *testing.T) { common.CoinType_Gas, 1000000, )) - assert.Error(t, err) - assert.ErrorIs(t, err, sdkerrors.ErrUnauthorized) + require.Error(t, err) + require.ErrorIs(t, err, sdkerrors.ErrUnauthorized) }) t.Run("should not deploy a new zrc20 with wrong decimal", func(t *testing.T) { @@ -128,8 +128,8 @@ func TestMsgServer_DeployFungibleCoinZRC20(t *testing.T) { common.CoinType_Gas, 1000000, )) - assert.Error(t, err) - assert.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) + require.Error(t, err) + require.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) }) t.Run("should not deploy a new zrc20 with invalid chain ID", func(t *testing.T) { @@ -151,8 +151,8 @@ func TestMsgServer_DeployFungibleCoinZRC20(t *testing.T) { common.CoinType_Gas, 1000000, )) - assert.Error(t, err) - assert.ErrorIs(t, err, observertypes.ErrSupportedChains) + require.Error(t, err) + require.ErrorIs(t, err, observertypes.ErrSupportedChains) }) t.Run("should not deploy an existing gas or erc20 contract", func(t *testing.T) { @@ -177,17 +177,17 @@ func TestMsgServer_DeployFungibleCoinZRC20(t *testing.T) { // Attempt to deploy the same gas token twice should result in error _, err := keeper.NewMsgServerImpl(*k).DeployFungibleCoinZRC20(ctx, deployMsg) - assert.NoError(t, err) + require.NoError(t, err) _, err = keeper.NewMsgServerImpl(*k).DeployFungibleCoinZRC20(ctx, deployMsg) - assert.Error(t, err) - assert.ErrorIs(t, err, types.ErrForeignCoinAlreadyExist) + require.Error(t, err) + require.ErrorIs(t, err, types.ErrForeignCoinAlreadyExist) // Similar to above, redeploying existing erc20 should also fail deployMsg.CoinType = common.CoinType_ERC20 _, err = keeper.NewMsgServerImpl(*k).DeployFungibleCoinZRC20(ctx, deployMsg) - assert.NoError(t, err) + require.NoError(t, err) _, err = keeper.NewMsgServerImpl(*k).DeployFungibleCoinZRC20(ctx, deployMsg) - assert.Error(t, err) - assert.ErrorIs(t, err, types.ErrForeignCoinAlreadyExist) + require.Error(t, err) + require.ErrorIs(t, err, types.ErrForeignCoinAlreadyExist) }) } diff --git a/x/fungible/keeper/msg_server_deploy_system_contract_test.go b/x/fungible/keeper/msg_server_deploy_system_contract_test.go index 601405d89c..86b9745021 100644 --- a/x/fungible/keeper/msg_server_deploy_system_contract_test.go +++ b/x/fungible/keeper/msg_server_deploy_system_contract_test.go @@ -8,7 +8,7 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ethcommon "github.com/ethereum/go-ethereum/common" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/fungible/keeper" @@ -25,8 +25,8 @@ func TestMsgServer_DeploySystemContracts(t *testing.T) { setAdminPolicies(ctx, zk, admin, observertypes.Policy_Type_group2) res, err := msgServer.DeploySystemContracts(ctx, types.NewMsgDeploySystemContracts(admin)) - assert.NoError(t, err) - assert.NotNil(t, res) + require.NoError(t, err) + require.NotNil(t, res) assertContractDeployment(t, sdkk.EvmKeeper, ctx, ethcommon.HexToAddress(res.UniswapV2Factory)) assertContractDeployment(t, sdkk.EvmKeeper, ctx, ethcommon.HexToAddress(res.Wzeta)) assertContractDeployment(t, sdkk.EvmKeeper, ctx, ethcommon.HexToAddress(res.UniswapV2Router)) @@ -42,7 +42,7 @@ func TestMsgServer_DeploySystemContracts(t *testing.T) { setAdminPolicies(ctx, zk, nonadmin, observertypes.Policy_Type_group1) _, err := msgServer.DeploySystemContracts(ctx, types.NewMsgDeploySystemContracts(nonadmin)) - assert.ErrorIs(t, err, sdkerrors.ErrUnauthorized) + require.ErrorIs(t, err, sdkerrors.ErrUnauthorized) }) t.Run("should fail if contract deployment fails", func(t *testing.T) { @@ -62,7 +62,7 @@ func TestMsgServer_DeploySystemContracts(t *testing.T) { ).Return(nil, errors.New("failed to estimate gas")) _, err := msgServer.DeploySystemContracts(ctx, types.NewMsgDeploySystemContracts(admin)) - assert.Error(t, err) - assert.Contains(t, err.Error(), "failed to deploy") + require.Error(t, err) + require.Contains(t, err.Error(), "failed to deploy") }) } diff --git a/x/fungible/keeper/msg_server_remove_foreign_coin_test.go b/x/fungible/keeper/msg_server_remove_foreign_coin_test.go index 848e609b2f..fedfe7315b 100644 --- a/x/fungible/keeper/msg_server_remove_foreign_coin_test.go +++ b/x/fungible/keeper/msg_server_remove_foreign_coin_test.go @@ -4,7 +4,7 @@ import ( "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/fungible/keeper" @@ -25,12 +25,12 @@ func TestMsgServer_RemoveForeignCoin(t *testing.T) { zrc20 := setupGasCoin(t, ctx, k, sdkk.EvmKeeper, chainID, "foo", "foo") _, found := k.GetForeignCoins(ctx, zrc20.Hex()) - assert.True(t, found) + require.True(t, found) _, err := msgServer.RemoveForeignCoin(ctx, types.NewMsgRemoveForeignCoin(admin, zrc20.Hex())) - assert.NoError(t, err) + require.NoError(t, err) _, found = k.GetForeignCoins(ctx, zrc20.Hex()) - assert.False(t, found) + require.False(t, found) }) t.Run("should fail if not admin", func(t *testing.T) { @@ -43,8 +43,8 @@ func TestMsgServer_RemoveForeignCoin(t *testing.T) { zrc20 := setupGasCoin(t, ctx, k, sdkk.EvmKeeper, chainID, "foo", "foo") _, err := msgServer.RemoveForeignCoin(ctx, types.NewMsgRemoveForeignCoin(sample.AccAddress(), zrc20.Hex())) - assert.Error(t, err) - assert.ErrorIs(t, err, sdkerrors.ErrUnauthorized) + require.Error(t, err) + require.ErrorIs(t, err, sdkerrors.ErrUnauthorized) }) t.Run("should fail if not found", func(t *testing.T) { @@ -55,7 +55,7 @@ func TestMsgServer_RemoveForeignCoin(t *testing.T) { setAdminPolicies(ctx, zk, admin, observertypes.Policy_Type_group2) _, err := msgServer.RemoveForeignCoin(ctx, types.NewMsgRemoveForeignCoin(admin, sample.EthAddress().Hex())) - assert.Error(t, err) - assert.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) + require.Error(t, err) + require.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) }) } diff --git a/x/fungible/keeper/msg_server_udpate_zrc20_liquidity_cap_test.go b/x/fungible/keeper/msg_server_udpate_zrc20_liquidity_cap_test.go index f42286928a..ea51fabc14 100644 --- a/x/fungible/keeper/msg_server_udpate_zrc20_liquidity_cap_test.go +++ b/x/fungible/keeper/msg_server_udpate_zrc20_liquidity_cap_test.go @@ -5,7 +5,7 @@ import ( "cosmossdk.io/math" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/fungible/keeper" @@ -32,11 +32,11 @@ func TestMsgServer_UpdateZRC20LiquidityCap(t *testing.T) { coinAddress, math.NewUint(42), )) - assert.NoError(t, err) + require.NoError(t, err) coin, found := k.GetForeignCoins(ctx, coinAddress) - assert.True(t, found) - assert.True(t, coin.LiquidityCap.Equal(math.NewUint(42)), "invalid liquidity cap", coin.LiquidityCap.String()) + require.True(t, found) + require.True(t, coin.LiquidityCap.Equal(math.NewUint(42)), "invalid liquidity cap", coin.LiquidityCap.String()) // can update liquidity cap again _, err = msgServer.UpdateZRC20LiquidityCap(ctx, types.NewMsgUpdateZRC20LiquidityCap( @@ -44,11 +44,11 @@ func TestMsgServer_UpdateZRC20LiquidityCap(t *testing.T) { coinAddress, math.NewUint(4200000), )) - assert.NoError(t, err) + require.NoError(t, err) coin, found = k.GetForeignCoins(ctx, coinAddress) - assert.True(t, found) - assert.True(t, coin.LiquidityCap.Equal(math.NewUint(4200000)), "invalid liquidity cap", coin.LiquidityCap.String()) + require.True(t, found) + require.True(t, coin.LiquidityCap.Equal(math.NewUint(4200000)), "invalid liquidity cap", coin.LiquidityCap.String()) // can set liquidity cap to 0 _, err = msgServer.UpdateZRC20LiquidityCap(ctx, types.NewMsgUpdateZRC20LiquidityCap( @@ -56,11 +56,11 @@ func TestMsgServer_UpdateZRC20LiquidityCap(t *testing.T) { coinAddress, math.NewUint(0), )) - assert.NoError(t, err) + require.NoError(t, err) coin, found = k.GetForeignCoins(ctx, coinAddress) - assert.True(t, found) - assert.True(t, coin.LiquidityCap.Equal(math.ZeroUint()), "invalid liquidity cap", coin.LiquidityCap.String()) + require.True(t, found) + require.True(t, coin.LiquidityCap.Equal(math.ZeroUint()), "invalid liquidity cap", coin.LiquidityCap.String()) // can set liquidity cap to nil _, err = msgServer.UpdateZRC20LiquidityCap(ctx, types.NewMsgUpdateZRC20LiquidityCap( @@ -68,11 +68,11 @@ func TestMsgServer_UpdateZRC20LiquidityCap(t *testing.T) { coinAddress, math.Uint{}, )) - assert.NoError(t, err) + require.NoError(t, err) coin, found = k.GetForeignCoins(ctx, coinAddress) - assert.True(t, found) - assert.True(t, coin.LiquidityCap.Equal(math.ZeroUint()), "invalid liquidity cap", coin.LiquidityCap.String()) + require.True(t, found) + require.True(t, coin.LiquidityCap.Equal(math.ZeroUint()), "invalid liquidity cap", coin.LiquidityCap.String()) }) t.Run("should fail if not admin", func(t *testing.T) { @@ -92,8 +92,8 @@ func TestMsgServer_UpdateZRC20LiquidityCap(t *testing.T) { coinAddress, math.NewUint(42), )) - assert.Error(t, err) - assert.ErrorIs(t, err, sdkerrors.ErrUnauthorized) + require.Error(t, err) + require.ErrorIs(t, err, sdkerrors.ErrUnauthorized) }) t.Run("should fail if zrc20 does not exist", func(t *testing.T) { @@ -109,7 +109,7 @@ func TestMsgServer_UpdateZRC20LiquidityCap(t *testing.T) { coinAddress, math.NewUint(42), )) - assert.Error(t, err) - assert.ErrorIs(t, err, types.ErrForeignCoinNotFound) + require.Error(t, err) + require.ErrorIs(t, err, types.ErrForeignCoinNotFound) }) } diff --git a/x/fungible/keeper/msg_server_update_contract_bytecode_test.go b/x/fungible/keeper/msg_server_update_contract_bytecode_test.go index f133236476..cb8e894eb0 100644 --- a/x/fungible/keeper/msg_server_update_contract_bytecode_test.go +++ b/x/fungible/keeper/msg_server_update_contract_bytecode_test.go @@ -10,8 +10,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/evmos/ethermint/x/evm/statedb" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" zetacommon "github.com/zeta-chain/zetacore/common" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -35,7 +35,7 @@ func codeHashFromAddress(t *testing.T, ctx sdk.Context, k *keeper.Keeper, contra res, err := k.CodeHash(ctx, &types.QueryCodeHashRequest{ Address: contractAddr, }) - assert.NoError(t, err) + require.NoError(t, err) return res.CodeHash } @@ -51,10 +51,10 @@ func TestKeeper_UpdateContractBytecode(t *testing.T) { // sample chainIDs and addresses chainList := zetacommon.DefaultChainsList() - assert.True(t, len(chainList) > 1) - assert.NotNil(t, chainList[0]) - assert.NotNil(t, chainList[1]) - assert.NotEqual(t, chainList[0].ChainId, chainList[1].ChainId) + require.True(t, len(chainList) > 1) + require.NotNil(t, chainList[0]) + require.NotNil(t, chainList[1]) + require.NotEqual(t, chainList[0].ChainId, chainList[1].ChainId) chainID1 := chainList[0].ChainId chainID2 := chainList[1].ChainId @@ -67,28 +67,28 @@ func TestKeeper_UpdateContractBytecode(t *testing.T) { // do some operation to populate the state _, err := k.DepositZRC20(ctx, zrc20, addr1, big.NewInt(100)) - assert.NoError(t, err) + require.NoError(t, err) _, err = k.DepositZRC20(ctx, zrc20, addr2, big.NewInt(200)) - assert.NoError(t, err) + require.NoError(t, err) // check the state checkState := func() { // state that should not change balance, err := k.BalanceOfZRC4(ctx, zrc20, addr1) - assert.NoError(t, err) - assert.Equal(t, int64(100), balance.Int64()) + require.NoError(t, err) + require.Equal(t, int64(100), balance.Int64()) balance, err = k.BalanceOfZRC4(ctx, zrc20, addr2) - assert.NoError(t, err) - assert.Equal(t, int64(200), balance.Int64()) + require.NoError(t, err) + require.Equal(t, int64(200), balance.Int64()) totalSupply, err := k.TotalSupplyZRC4(ctx, zrc20) - assert.NoError(t, err) - assert.Equal(t, int64(10000300), totalSupply.Int64()) // 10000000 minted on deploy + require.NoError(t, err) + require.Equal(t, int64(10000300), totalSupply.Int64()) // 10000000 minted on deploy } checkState() chainID, err := k.QueryChainIDFromContract(ctx, zrc20) - assert.NoError(t, err) - assert.Equal(t, chainID1, chainID.Int64()) + require.NoError(t, err) + require.Equal(t, chainID1, chainID.Int64()) // deploy new zrc20 newCodeAddress, err := k.DeployZRC20Contract( @@ -101,7 +101,7 @@ func TestKeeper_UpdateContractBytecode(t *testing.T) { "beta", big.NewInt(90_000), ) - assert.NoError(t, err) + require.NoError(t, err) codeHash := codeHashFromAddress(t, ctx, k, newCodeAddress.Hex()) // update the bytecode @@ -110,29 +110,29 @@ func TestKeeper_UpdateContractBytecode(t *testing.T) { zrc20.Hex(), codeHash, )) - assert.NoError(t, err) + require.NoError(t, err) // check the returned new bytecode hash matches the one in the account acct := sdkk.EvmKeeper.GetAccount(ctx, zrc20) - assert.Equal(t, acct.CodeHash, ethcommon.HexToHash(codeHash).Bytes()) + require.Equal(t, acct.CodeHash, ethcommon.HexToHash(codeHash).Bytes()) // check the state // balances and total supply should remain // BYTECODE value is immutable and therefore part of the code, this value should change checkState() chainID, err = k.QueryChainIDFromContract(ctx, zrc20) - assert.NoError(t, err) - assert.Equal(t, chainID2, chainID.Int64()) + require.NoError(t, err) + require.Equal(t, chainID2, chainID.Int64()) // can continue to interact with the contract _, err = k.DepositZRC20(ctx, zrc20, addr1, big.NewInt(1000)) - assert.NoError(t, err) + require.NoError(t, err) balance, err := k.BalanceOfZRC4(ctx, zrc20, addr1) - assert.NoError(t, err) - assert.Equal(t, int64(1100), balance.Int64()) + require.NoError(t, err) + require.Equal(t, int64(1100), balance.Int64()) totalSupply, err := k.TotalSupplyZRC4(ctx, zrc20) - assert.NoError(t, err) - assert.Equal(t, int64(10001300), totalSupply.Int64()) + require.NoError(t, err) + require.Equal(t, int64(10001300), totalSupply.Int64()) // can change again bytecode newCodeAddress, err = k.DeployZRC20Contract( @@ -146,22 +146,22 @@ func TestKeeper_UpdateContractBytecode(t *testing.T) { big.NewInt(90_000), ) codeHash = codeHashFromAddress(t, ctx, k, newCodeAddress.Hex()) - assert.NoError(t, err) + require.NoError(t, err) _, err = msgServer.UpdateContractBytecode(ctx, types.NewMsgUpdateContractBytecode( admin, zrc20.Hex(), codeHash, )) - assert.NoError(t, err) + require.NoError(t, err) balance, err = k.BalanceOfZRC4(ctx, zrc20, addr1) - assert.NoError(t, err) - assert.Equal(t, int64(1100), balance.Int64()) + require.NoError(t, err) + require.Equal(t, int64(1100), balance.Int64()) totalSupply, err = k.TotalSupplyZRC4(ctx, zrc20) - assert.NoError(t, err) - assert.Equal(t, int64(10001300), totalSupply.Int64()) + require.NoError(t, err) + require.Equal(t, int64(10001300), totalSupply.Int64()) chainID, err = k.QueryChainIDFromContract(ctx, zrc20) - assert.NoError(t, err) - assert.Equal(t, chainID1, chainID.Int64()) + require.NoError(t, err) + require.Equal(t, chainID1, chainID.Int64()) }) t.Run("can update the bytecode of the wzeta connector contract", func(t *testing.T) { @@ -177,8 +177,8 @@ func TestKeeper_UpdateContractBytecode(t *testing.T) { // deploy a new connector that will become official connector newConnector, err := k.DeployConnectorZEVM(ctx, wzeta) - assert.NoError(t, err) - assert.NotEmpty(t, newConnector) + require.NoError(t, err) + require.NotEmpty(t, newConnector) assertContractDeployment(t, sdkk.EvmKeeper, ctx, newConnector) // can update the bytecode of the new connector with the old connector contract @@ -187,7 +187,7 @@ func TestKeeper_UpdateContractBytecode(t *testing.T) { newConnector.Hex(), codeHash, )) - assert.NoError(t, err) + require.NoError(t, err) }) t.Run("should fail if unauthorized", func(t *testing.T) { @@ -199,7 +199,7 @@ func TestKeeper_UpdateContractBytecode(t *testing.T) { sample.EthAddress().Hex(), sample.Hash().Hex(), )) - assert.ErrorIs(t, err, sdkerrors.ErrUnauthorized) + require.ErrorIs(t, err, sdkerrors.ErrUnauthorized) }) t.Run("should fail invalid contract address", func(t *testing.T) { @@ -214,7 +214,7 @@ func TestKeeper_UpdateContractBytecode(t *testing.T) { ContractAddress: "invalid", NewCodeHash: sample.Hash().Hex(), }) - assert.ErrorIs(t, err, sdkerrors.ErrInvalidAddress) + require.ErrorIs(t, err, sdkerrors.ErrInvalidAddress) }) t.Run("should fail if can't get contract account", func(t *testing.T) { @@ -238,7 +238,7 @@ func TestKeeper_UpdateContractBytecode(t *testing.T) { contractAddr.Hex(), sample.Hash().Hex(), )) - assert.ErrorIs(t, err, types.ErrContractNotFound) + require.ErrorIs(t, err, types.ErrContractNotFound) mockEVMKeeper.AssertExpectations(t) }) @@ -258,7 +258,7 @@ func TestKeeper_UpdateContractBytecode(t *testing.T) { wzeta.Hex(), sample.Hash().Hex(), )) - assert.ErrorIs(t, err, types.ErrInvalidContract) + require.ErrorIs(t, err, types.ErrInvalidContract) }) t.Run("should fail if system contract not found", func(t *testing.T) { @@ -279,7 +279,7 @@ func TestKeeper_UpdateContractBytecode(t *testing.T) { connector.Hex(), sample.Hash().Hex(), )) - assert.ErrorIs(t, err, types.ErrSystemContractNotFound) + require.ErrorIs(t, err, types.ErrSystemContractNotFound) }) t.Run("should fail if can't set account with new bytecode", func(t *testing.T) { @@ -316,7 +316,7 @@ func TestKeeper_UpdateContractBytecode(t *testing.T) { contractAddr.Hex(), newCodeHash, )) - assert.ErrorIs(t, err, types.ErrSetBytecode) + require.ErrorIs(t, err, types.ErrSetBytecode) mockEVMKeeper.AssertExpectations(t) }) diff --git a/x/fungible/keeper/msg_server_update_system_contract_test.go b/x/fungible/keeper/msg_server_update_system_contract_test.go index 028d0ed215..b464da209c 100644 --- a/x/fungible/keeper/msg_server_update_system_contract_test.go +++ b/x/fungible/keeper/msg_server_update_system_contract_test.go @@ -6,7 +6,7 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/ethereum/go-ethereum/common" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/systemcontract.sol" "github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/zrc20.sol" zetacommon "github.com/zeta-chain/zetacore/common" @@ -27,20 +27,20 @@ func TestKeeper_UpdateSystemContract(t *testing.T) { queryZRC20SystemContract := func(contract common.Address) string { abi, err := zrc20.ZRC20MetaData.GetAbi() - assert.NoError(t, err) + require.NoError(t, err) res, err := k.CallEVM(ctx, *abi, types.ModuleAddressEVM, contract, keeper.BigIntZero, nil, false, false, "SYSTEM_CONTRACT_ADDRESS") - assert.NoError(t, err) + require.NoError(t, err) unpacked, err := abi.Unpack("SYSTEM_CONTRACT_ADDRESS", res.Ret) - assert.NoError(t, err) + require.NoError(t, err) address, ok := unpacked[0].(common.Address) - assert.True(t, ok) + require.True(t, ok) return address.Hex() } chains := zetacommon.DefaultChainsList() - assert.True(t, len(chains) > 1) - assert.NotNil(t, chains[0]) - assert.NotNil(t, chains[1]) + require.True(t, len(chains) > 1) + require.NotNil(t, chains[0]) + require.NotNil(t, chains[1]) chainID1 := chains[0].ChainId chainID2 := chains[1].ChainId @@ -50,28 +50,28 @@ func TestKeeper_UpdateSystemContract(t *testing.T) { // deploy a new system contracts newSystemContract, err := k.DeployContract(ctx, systemcontract.SystemContractMetaData, wzeta, factory, router) - assert.NoError(t, err) - assert.NotEqual(t, oldSystemContract, newSystemContract) + require.NoError(t, err) + require.NotEqual(t, oldSystemContract, newSystemContract) // can update the system contract _, err = msgServer.UpdateSystemContract(ctx, types.NewMsgUpdateSystemContract(admin, newSystemContract.Hex())) - assert.NoError(t, err) + require.NoError(t, err) // can retrieve the system contract sc, found := k.GetSystemContract(ctx) - assert.True(t, found) - assert.Equal(t, newSystemContract.Hex(), sc.SystemContract) + require.True(t, found) + require.Equal(t, newSystemContract.Hex(), sc.SystemContract) // check gas updated foundGas1, err := k.QuerySystemContractGasCoinZRC20(ctx, big.NewInt(chainID1)) - assert.NoError(t, err) - assert.Equal(t, gas1, foundGas1) + require.NoError(t, err) + require.Equal(t, gas1, foundGas1) foundGas2, err := k.QuerySystemContractGasCoinZRC20(ctx, big.NewInt(chainID2)) - assert.NoError(t, err) - assert.Equal(t, gas2, foundGas2) + require.NoError(t, err) + require.Equal(t, gas2, foundGas2) - assert.Equal(t, newSystemContract.Hex(), queryZRC20SystemContract(gas1)) - assert.Equal(t, newSystemContract.Hex(), queryZRC20SystemContract(gas2)) + require.Equal(t, newSystemContract.Hex(), queryZRC20SystemContract(gas1)) + require.Equal(t, newSystemContract.Hex(), queryZRC20SystemContract(gas2)) }) t.Run("should not update the system contract if not admin", func(t *testing.T) { @@ -82,13 +82,13 @@ func TestKeeper_UpdateSystemContract(t *testing.T) { // deploy a new system contracts wzeta, factory, router, _, oldSystemContract := deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) newSystemContract, err := k.DeployContract(ctx, systemcontract.SystemContractMetaData, wzeta, factory, router) - assert.NoError(t, err) - assert.NotEqual(t, oldSystemContract, newSystemContract) + require.NoError(t, err) + require.NotEqual(t, oldSystemContract, newSystemContract) // should not update the system contract if not admin _, err = msgServer.UpdateSystemContract(ctx, types.NewMsgUpdateSystemContract(sample.AccAddress(), newSystemContract.Hex())) - assert.Error(t, err) - assert.ErrorIs(t, err, sdkerrors.ErrUnauthorized) + require.Error(t, err) + require.ErrorIs(t, err, sdkerrors.ErrUnauthorized) }) t.Run("should not update the system contract if invalid address", func(t *testing.T) { @@ -101,12 +101,12 @@ func TestKeeper_UpdateSystemContract(t *testing.T) { // deploy a new system contracts wzeta, factory, router, _, oldSystemContract := deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) newSystemContract, err := k.DeployContract(ctx, systemcontract.SystemContractMetaData, wzeta, factory, router) - assert.NoError(t, err) - assert.NotEqual(t, oldSystemContract, newSystemContract) + require.NoError(t, err) + require.NotEqual(t, oldSystemContract, newSystemContract) // should not update the system contract if invalid address _, err = msgServer.UpdateSystemContract(ctx, types.NewMsgUpdateSystemContract(admin, "invalid")) - assert.Error(t, err) - assert.ErrorIs(t, err, sdkerrors.ErrInvalidAddress) + require.Error(t, err) + require.ErrorIs(t, err, sdkerrors.ErrInvalidAddress) }) } diff --git a/x/fungible/keeper/msg_server_update_zrc20_paused_status_test.go b/x/fungible/keeper/msg_server_update_zrc20_paused_status_test.go index bd6b69874e..bc4238a780 100644 --- a/x/fungible/keeper/msg_server_update_zrc20_paused_status_test.go +++ b/x/fungible/keeper/msg_server_update_zrc20_paused_status_test.go @@ -4,7 +4,7 @@ import ( "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/fungible/keeper" @@ -20,13 +20,13 @@ func TestKeeper_UpdateZRC20PausedStatus(t *testing.T) { assertUnpaused := func(zrc20 string) { fc, found := k.GetForeignCoins(ctx, zrc20) - assert.True(t, found) - assert.False(t, fc.Paused) + require.True(t, found) + require.False(t, fc.Paused) } assertPaused := func(zrc20 string) { fc, found := k.GetForeignCoins(ctx, zrc20) - assert.True(t, found) - assert.True(t, fc.Paused) + require.True(t, found) + require.True(t, fc.Paused) } // setup zrc20 @@ -49,7 +49,7 @@ func TestKeeper_UpdateZRC20PausedStatus(t *testing.T) { }, types.UpdatePausedStatusAction_PAUSE, )) - assert.NoError(t, err) + require.NoError(t, err) assertPaused(zrc20A) assertPaused(zrc20B) assertUnpaused(zrc20C) @@ -64,7 +64,7 @@ func TestKeeper_UpdateZRC20PausedStatus(t *testing.T) { }, types.UpdatePausedStatusAction_UNPAUSE, )) - assert.NoError(t, err) + require.NoError(t, err) assertUnpaused(zrc20A) assertPaused(zrc20B) assertUnpaused(zrc20C) @@ -79,7 +79,7 @@ func TestKeeper_UpdateZRC20PausedStatus(t *testing.T) { }, types.UpdatePausedStatusAction_PAUSE, )) - assert.NoError(t, err) + require.NoError(t, err) assertUnpaused(zrc20A) assertPaused(zrc20B) assertUnpaused(zrc20C) @@ -94,7 +94,7 @@ func TestKeeper_UpdateZRC20PausedStatus(t *testing.T) { }, types.UpdatePausedStatusAction_UNPAUSE, )) - assert.NoError(t, err) + require.NoError(t, err) assertUnpaused(zrc20A) assertPaused(zrc20B) assertUnpaused(zrc20C) @@ -111,7 +111,7 @@ func TestKeeper_UpdateZRC20PausedStatus(t *testing.T) { }, types.UpdatePausedStatusAction_PAUSE, )) - assert.NoError(t, err) + require.NoError(t, err) assertPaused(zrc20A) assertPaused(zrc20B) assertPaused(zrc20C) @@ -128,7 +128,7 @@ func TestKeeper_UpdateZRC20PausedStatus(t *testing.T) { }, types.UpdatePausedStatusAction_UNPAUSE, )) - assert.NoError(t, err) + require.NoError(t, err) assertUnpaused(zrc20A) assertUnpaused(zrc20B) assertUnpaused(zrc20C) @@ -141,10 +141,10 @@ func TestKeeper_UpdateZRC20PausedStatus(t *testing.T) { setAdminPolicies(ctx, zk, admin, observertypes.Policy_Type_group1) invalidMsg := types.NewMsgUpdateZRC20PausedStatus(admin, []string{}, types.UpdatePausedStatusAction_PAUSE) - assert.ErrorIs(t, invalidMsg.ValidateBasic(), sdkerrors.ErrInvalidRequest) + require.ErrorIs(t, invalidMsg.ValidateBasic(), sdkerrors.ErrInvalidRequest) _, err := msgServer.UpdateZRC20PausedStatus(ctx, invalidMsg) - assert.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) + require.ErrorIs(t, err, sdkerrors.ErrInvalidRequest) }) t.Run("should fail if not authorized", func(t *testing.T) { @@ -166,7 +166,7 @@ func TestKeeper_UpdateZRC20PausedStatus(t *testing.T) { types.UpdatePausedStatusAction_UNPAUSE, )) - assert.ErrorIs(t, err, sdkerrors.ErrUnauthorized) + require.ErrorIs(t, err, sdkerrors.ErrUnauthorized) }) t.Run("should fail if zrc20 does not exist", func(t *testing.T) { @@ -188,6 +188,6 @@ func TestKeeper_UpdateZRC20PausedStatus(t *testing.T) { }, types.UpdatePausedStatusAction_PAUSE, )) - assert.ErrorIs(t, err, types.ErrForeignCoinNotFound) + require.ErrorIs(t, err, types.ErrForeignCoinNotFound) }) } diff --git a/x/fungible/keeper/msg_server_update_zrc20_withdraw_fee_test.go b/x/fungible/keeper/msg_server_update_zrc20_withdraw_fee_test.go index 288f158c31..108c70c664 100644 --- a/x/fungible/keeper/msg_server_update_zrc20_withdraw_fee_test.go +++ b/x/fungible/keeper/msg_server_update_zrc20_withdraw_fee_test.go @@ -9,8 +9,8 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" evmtypes "github.com/evmos/ethermint/x/evm/types" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/require" "github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/zrc20.sol" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -36,8 +36,8 @@ func TestKeeper_UpdateZRC20WithdrawFee(t *testing.T) { // initial protocol fee is zero protocolFee, err := k.QueryProtocolFlatFee(ctx, zrc20Addr) - assert.NoError(t, err) - assert.Zero(t, protocolFee.Uint64()) + require.NoError(t, err) + require.Zero(t, protocolFee.Uint64()) // can update the protocol fee and gas limit _, err = msgServer.UpdateZRC20WithdrawFee(ctx, types.NewMsgUpdateZRC20WithdrawFee( @@ -46,15 +46,15 @@ func TestKeeper_UpdateZRC20WithdrawFee(t *testing.T) { math.NewUint(42), math.NewUint(42), )) - assert.NoError(t, err) + require.NoError(t, err) // can query the updated fee protocolFee, err = k.QueryProtocolFlatFee(ctx, zrc20Addr) - assert.NoError(t, err) - assert.Equal(t, uint64(42), protocolFee.Uint64()) + require.NoError(t, err) + require.Equal(t, uint64(42), protocolFee.Uint64()) gasLimit, err := k.QueryGasLimit(ctx, zrc20Addr) - assert.NoError(t, err) - assert.Equal(t, uint64(42), gasLimit.Uint64()) + require.NoError(t, err) + require.Equal(t, uint64(42), gasLimit.Uint64()) // can update protocol fee only _, err = msgServer.UpdateZRC20WithdrawFee(ctx, types.NewMsgUpdateZRC20WithdrawFee( @@ -63,13 +63,13 @@ func TestKeeper_UpdateZRC20WithdrawFee(t *testing.T) { math.NewUint(43), math.Uint{}, )) - assert.NoError(t, err) + require.NoError(t, err) protocolFee, err = k.QueryProtocolFlatFee(ctx, zrc20Addr) - assert.NoError(t, err) - assert.Equal(t, uint64(43), protocolFee.Uint64()) + require.NoError(t, err) + require.Equal(t, uint64(43), protocolFee.Uint64()) gasLimit, err = k.QueryGasLimit(ctx, zrc20Addr) - assert.NoError(t, err) - assert.Equal(t, uint64(42), gasLimit.Uint64()) + require.NoError(t, err) + require.Equal(t, uint64(42), gasLimit.Uint64()) // can update gas limit only _, err = msgServer.UpdateZRC20WithdrawFee(ctx, types.NewMsgUpdateZRC20WithdrawFee( @@ -78,13 +78,13 @@ func TestKeeper_UpdateZRC20WithdrawFee(t *testing.T) { math.Uint{}, math.NewUint(44), )) - assert.NoError(t, err) + require.NoError(t, err) protocolFee, err = k.QueryProtocolFlatFee(ctx, zrc20Addr) - assert.NoError(t, err) - assert.Equal(t, uint64(43), protocolFee.Uint64()) + require.NoError(t, err) + require.Equal(t, uint64(43), protocolFee.Uint64()) gasLimit, err = k.QueryGasLimit(ctx, zrc20Addr) - assert.NoError(t, err) - assert.Equal(t, uint64(44), gasLimit.Uint64()) + require.NoError(t, err) + require.Equal(t, uint64(44), gasLimit.Uint64()) }) t.Run("should fail if not authorized", func(t *testing.T) { @@ -97,7 +97,7 @@ func TestKeeper_UpdateZRC20WithdrawFee(t *testing.T) { math.NewUint(42), math.Uint{}, )) - assert.ErrorIs(t, err, sdkerrors.ErrUnauthorized) + require.ErrorIs(t, err, sdkerrors.ErrUnauthorized) }) t.Run("should fail if invalid zrc20 address", func(t *testing.T) { @@ -112,7 +112,7 @@ func TestKeeper_UpdateZRC20WithdrawFee(t *testing.T) { math.NewUint(42), math.Uint{}, )) - assert.ErrorIs(t, err, sdkerrors.ErrInvalidAddress) + require.ErrorIs(t, err, sdkerrors.ErrInvalidAddress) }) t.Run("should fail if can't retrieve the foreign coin", func(t *testing.T) { @@ -127,7 +127,7 @@ func TestKeeper_UpdateZRC20WithdrawFee(t *testing.T) { math.NewUint(42), math.Uint{}, )) - assert.ErrorIs(t, err, types.ErrForeignCoinNotFound) + require.ErrorIs(t, err, types.ErrForeignCoinNotFound) }) t.Run("should fail if can't query old fee", func(t *testing.T) { @@ -148,7 +148,7 @@ func TestKeeper_UpdateZRC20WithdrawFee(t *testing.T) { math.NewUint(42), math.Uint{}, )) - assert.ErrorIs(t, err, types.ErrContractCall) + require.ErrorIs(t, err, types.ErrContractCall) }) t.Run("should fail if contract call for setting new protocol fee fails", func(t *testing.T) { @@ -173,9 +173,9 @@ func TestKeeper_UpdateZRC20WithdrawFee(t *testing.T) { // this is the query (commit == false) zrc20ABI, err := zrc20.ZRC20MetaData.GetAbi() - assert.NoError(t, err) + require.NoError(t, err) protocolFlatFee, err := zrc20ABI.Methods["PROTOCOL_FLAT_FEE"].Outputs.Pack(big.NewInt(42)) - assert.NoError(t, err) + require.NoError(t, err) mockEVMKeeper.On( "ApplyMessage", mock.Anything, @@ -185,7 +185,7 @@ func TestKeeper_UpdateZRC20WithdrawFee(t *testing.T) { ).Return(&evmtypes.MsgEthereumTxResponse{Ret: protocolFlatFee}, nil) gasLimit, err := zrc20ABI.Methods["GAS_LIMIT"].Outputs.Pack(big.NewInt(42)) - assert.NoError(t, err) + require.NoError(t, err) mockEVMKeeper.On( "ApplyMessage", mock.Anything, @@ -209,7 +209,7 @@ func TestKeeper_UpdateZRC20WithdrawFee(t *testing.T) { math.NewUint(42), math.Uint{}, )) - assert.ErrorIs(t, err, types.ErrContractCall) + require.ErrorIs(t, err, types.ErrContractCall) mockEVMKeeper.AssertExpectations(t) }) @@ -236,9 +236,9 @@ func TestKeeper_UpdateZRC20WithdrawFee(t *testing.T) { // this is the query (commit == false) zrc20ABI, err := zrc20.ZRC20MetaData.GetAbi() - assert.NoError(t, err) + require.NoError(t, err) protocolFlatFee, err := zrc20ABI.Methods["PROTOCOL_FLAT_FEE"].Outputs.Pack(big.NewInt(42)) - assert.NoError(t, err) + require.NoError(t, err) mockEVMKeeper.On( "ApplyMessage", mock.Anything, @@ -248,7 +248,7 @@ func TestKeeper_UpdateZRC20WithdrawFee(t *testing.T) { ).Return(&evmtypes.MsgEthereumTxResponse{Ret: protocolFlatFee}, nil) gasLimit, err := zrc20ABI.Methods["GAS_LIMIT"].Outputs.Pack(big.NewInt(42)) - assert.NoError(t, err) + require.NoError(t, err) mockEVMKeeper.On( "ApplyMessage", mock.Anything, @@ -272,7 +272,7 @@ func TestKeeper_UpdateZRC20WithdrawFee(t *testing.T) { math.Uint{}, math.NewUint(42), )) - assert.ErrorIs(t, err, types.ErrContractCall) + require.ErrorIs(t, err, types.ErrContractCall) mockEVMKeeper.AssertExpectations(t) }) diff --git a/x/fungible/keeper/params_test.go b/x/fungible/keeper/params_test.go index 377e13b4ce..b3b9497a74 100644 --- a/x/fungible/keeper/params_test.go +++ b/x/fungible/keeper/params_test.go @@ -3,7 +3,7 @@ package keeper_test import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" testkeeper "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/x/fungible/types" ) @@ -14,5 +14,5 @@ func TestGetParams(t *testing.T) { k.SetParams(ctx, params) - assert.EqualValues(t, params, k.GetParams(ctx)) + require.EqualValues(t, params, k.GetParams(ctx)) } diff --git a/x/fungible/keeper/system_contract_test.go b/x/fungible/keeper/system_contract_test.go index 3148b8c44c..3874f52435 100644 --- a/x/fungible/keeper/system_contract_test.go +++ b/x/fungible/keeper/system_contract_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/ethereum/go-ethereum/common" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/fungible/types" @@ -15,13 +15,13 @@ func TestKeeper_GetSystemContract(t *testing.T) { k, ctx, _, _ := keepertest.FungibleKeeper(t) k.SetSystemContract(ctx, types.SystemContract{SystemContract: "test"}) val, found := k.GetSystemContract(ctx) - assert.True(t, found) - assert.Equal(t, types.SystemContract{SystemContract: "test"}, val) + require.True(t, found) + require.Equal(t, types.SystemContract{SystemContract: "test"}, val) // can remove contract k.RemoveSystemContract(ctx) _, found = k.GetSystemContract(ctx) - assert.False(t, found) + require.False(t, found) } func TestKeeper_GetSystemContractAddress(t *testing.T) { @@ -29,13 +29,13 @@ func TestKeeper_GetSystemContractAddress(t *testing.T) { k.GetAuthKeeper().GetModuleAccount(ctx, types.ModuleName) _, err := k.GetSystemContractAddress(ctx) - assert.Error(t, err) - assert.ErrorIs(t, err, types.ErrStateVariableNotFound) + require.Error(t, err) + require.ErrorIs(t, err, types.ErrStateVariableNotFound) _, _, _, _, systemContract := deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) found, err := k.GetSystemContractAddress(ctx) - assert.NoError(t, err) - assert.Equal(t, systemContract, found) + require.NoError(t, err) + require.Equal(t, systemContract, found) } func TestKeeper_GetWZetaContractAddress(t *testing.T) { @@ -43,13 +43,13 @@ func TestKeeper_GetWZetaContractAddress(t *testing.T) { k.GetAuthKeeper().GetModuleAccount(ctx, types.ModuleName) _, err := k.GetWZetaContractAddress(ctx) - assert.Error(t, err) - assert.ErrorIs(t, err, types.ErrStateVariableNotFound) + require.Error(t, err) + require.ErrorIs(t, err, types.ErrStateVariableNotFound) wzeta, _, _, _, _ := deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) found, err := k.GetWZetaContractAddress(ctx) - assert.NoError(t, err) - assert.Equal(t, wzeta, found) + require.NoError(t, err) + require.Equal(t, wzeta, found) } func TestKeeper_GetUniswapV2FactoryAddress(t *testing.T) { @@ -57,13 +57,13 @@ func TestKeeper_GetUniswapV2FactoryAddress(t *testing.T) { k.GetAuthKeeper().GetModuleAccount(ctx, types.ModuleName) _, err := k.GetUniswapV2FactoryAddress(ctx) - assert.Error(t, err) - assert.ErrorIs(t, err, types.ErrStateVariableNotFound) + require.Error(t, err) + require.ErrorIs(t, err, types.ErrStateVariableNotFound) _, factory, _, _, _ := deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) found, err := k.GetUniswapV2FactoryAddress(ctx) - assert.NoError(t, err) - assert.Equal(t, factory, found) + require.NoError(t, err) + require.Equal(t, factory, found) } func TestKeeper_GetUniswapV2Router02Address(t *testing.T) { @@ -71,13 +71,13 @@ func TestKeeper_GetUniswapV2Router02Address(t *testing.T) { k.GetAuthKeeper().GetModuleAccount(ctx, types.ModuleName) _, err := k.GetUniswapV2Router02Address(ctx) - assert.Error(t, err) - assert.ErrorIs(t, err, types.ErrStateVariableNotFound) + require.Error(t, err) + require.ErrorIs(t, err, types.ErrStateVariableNotFound) _, _, router, _, _ := deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) found, err := k.GetUniswapV2Router02Address(ctx) - assert.NoError(t, err) - assert.Equal(t, router, found) + require.NoError(t, err) + require.Equal(t, router, found) } func TestKeeper_CallWZetaDeposit(t *testing.T) { @@ -89,23 +89,23 @@ func TestKeeper_CallWZetaDeposit(t *testing.T) { ethAddr := common.BytesToAddress(addr.Bytes()) coins := sample.Coins() err := sdkk.BankKeeper.MintCoins(ctx, types.ModuleName, sample.Coins()) - assert.NoError(t, err) + require.NoError(t, err) err = sdkk.BankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, addr, coins) - assert.NoError(t, err) + require.NoError(t, err) // fail if no system contract err = k.CallWZetaDeposit(ctx, ethAddr, big.NewInt(42)) - assert.Error(t, err) + require.Error(t, err) deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) // deposit err = k.CallWZetaDeposit(ctx, ethAddr, big.NewInt(42)) - assert.NoError(t, err) + require.NoError(t, err) balance, err := k.QueryWZetaBalanceOf(ctx, ethAddr) - assert.NoError(t, err) - assert.Equal(t, big.NewInt(42), balance) + require.NoError(t, err) + require.Equal(t, big.NewInt(42), balance) } func TestKeeper_QuerySystemContractGasCoinZRC20(t *testing.T) { @@ -114,13 +114,13 @@ func TestKeeper_QuerySystemContractGasCoinZRC20(t *testing.T) { chainID := getValidChainID(t) _, err := k.QuerySystemContractGasCoinZRC20(ctx, big.NewInt(chainID)) - assert.Error(t, err) - assert.ErrorIs(t, err, types.ErrStateVariableNotFound) + require.Error(t, err) + require.ErrorIs(t, err, types.ErrStateVariableNotFound) deploySystemContracts(t, ctx, k, sdkk.EvmKeeper) zrc20 := setupGasCoin(t, ctx, k, sdkk.EvmKeeper, chainID, "foobar", "foobar") found, err := k.QuerySystemContractGasCoinZRC20(ctx, big.NewInt(chainID)) - assert.NoError(t, err) - assert.Equal(t, zrc20, found) + require.NoError(t, err) + require.Equal(t, zrc20, found) } diff --git a/x/fungible/keeper/zeta_test.go b/x/fungible/keeper/zeta_test.go index 4eea6b70ad..cec34d06ea 100644 --- a/x/fungible/keeper/zeta_test.go +++ b/x/fungible/keeper/zeta_test.go @@ -6,7 +6,7 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/cmd/zetacored/config" testkeeper "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -20,12 +20,12 @@ func TestKeeper_MintZetaToEVMAccount(t *testing.T) { acc := sample.Bech32AccAddress() bal := sdkk.BankKeeper.GetBalance(ctx, acc, config.BaseDenom) - assert.True(t, bal.IsZero()) + require.True(t, bal.IsZero()) err := k.MintZetaToEVMAccount(ctx, acc, big.NewInt(42)) - assert.NoError(t, err) + require.NoError(t, err) bal = sdkk.BankKeeper.GetBalance(ctx, acc, config.BaseDenom) - assert.True(t, bal.Amount.Equal(sdk.NewInt(42))) + require.True(t, bal.Amount.Equal(sdk.NewInt(42))) }) coins42 := sdk.NewCoins(sdk.NewCoin(config.BaseDenom, sdk.NewInt(42))) @@ -43,7 +43,7 @@ func TestKeeper_MintZetaToEVMAccount(t *testing.T) { ).Return(errors.New("error")) err := k.MintZetaToEVMAccount(ctx, sample.Bech32AccAddress(), big.NewInt(42)) - assert.Error(t, err) + require.Error(t, err) mockBankKeeper.AssertExpectations(t) }) @@ -70,7 +70,7 @@ func TestKeeper_MintZetaToEVMAccount(t *testing.T) { ).Return(errors.New("error")) err := k.MintZetaToEVMAccount(ctx, acc, big.NewInt(42)) - assert.Error(t, err) + require.Error(t, err) mockBankKeeper.AssertExpectations(t) }) diff --git a/x/fungible/types/evm_test.go b/x/fungible/types/evm_test.go index 4e81bb3562..0be4d916da 100644 --- a/x/fungible/types/evm_test.go +++ b/x/fungible/types/evm_test.go @@ -7,16 +7,16 @@ import ( "github.com/ethereum/go-ethereum/core/vm" evmtypes "github.com/evmos/ethermint/x/evm/types" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/x/fungible/types" ) func TestIsContractReverted(t *testing.T) { - assert.True(t, types.IsContractReverted(nil, vm.ErrExecutionReverted)) - assert.True(t, types.IsContractReverted(nil, fmt.Errorf("foo : %s", vm.ErrExecutionReverted.Error()))) - assert.True(t, types.IsContractReverted(&evmtypes.MsgEthereumTxResponse{VmError: "foo"}, nil)) + require.True(t, types.IsContractReverted(nil, vm.ErrExecutionReverted)) + require.True(t, types.IsContractReverted(nil, fmt.Errorf("foo : %s", vm.ErrExecutionReverted.Error()))) + require.True(t, types.IsContractReverted(&evmtypes.MsgEthereumTxResponse{VmError: "foo"}, nil)) - assert.False(t, types.IsContractReverted(nil, nil)) - assert.False(t, types.IsContractReverted(nil, errors.New("foo"))) - assert.False(t, types.IsContractReverted(&evmtypes.MsgEthereumTxResponse{VmError: ""}, nil)) + require.False(t, types.IsContractReverted(nil, nil)) + require.False(t, types.IsContractReverted(nil, errors.New("foo"))) + require.False(t, types.IsContractReverted(&evmtypes.MsgEthereumTxResponse{VmError: ""}, nil)) } diff --git a/x/fungible/types/gas_stablity_pool_test.go b/x/fungible/types/gas_stablity_pool_test.go index dfeac5b484..c0ec0000f5 100644 --- a/x/fungible/types/gas_stablity_pool_test.go +++ b/x/fungible/types/gas_stablity_pool_test.go @@ -3,16 +3,16 @@ package types_test import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/x/fungible/types" ) func TestGetGasStabilityPoolAddress(t *testing.T) { address := types.GasStabilityPoolAddress() - assert.False(t, address.Empty()) + require.False(t, address.Empty()) } func TestGetGasStabilityPoolAddressEVM(t *testing.T) { address := types.GasStabilityPoolAddressEVM() - assert.NotEmpty(t, address) + require.NotEmpty(t, address) } diff --git a/x/fungible/types/genesis_test.go b/x/fungible/types/genesis_test.go index a5a16ba6f7..57927528af 100644 --- a/x/fungible/types/genesis_test.go +++ b/x/fungible/types/genesis_test.go @@ -3,7 +3,7 @@ package types_test import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/x/fungible/types" ) @@ -51,9 +51,9 @@ func TestGenesisState_Validate(t *testing.T) { t.Run(tc.desc, func(t *testing.T) { err := tc.genState.Validate() if tc.valid { - assert.NoError(t, err) + require.NoError(t, err) } else { - assert.Error(t, err) + require.Error(t, err) } }) } diff --git a/x/fungible/types/message_deploy_fungible_coin_zrc20_test.go b/x/fungible/types/message_deploy_fungible_coin_zrc20_test.go index 9addfd0eb5..e107af7781 100644 --- a/x/fungible/types/message_deploy_fungible_coin_zrc20_test.go +++ b/x/fungible/types/message_deploy_fungible_coin_zrc20_test.go @@ -4,7 +4,7 @@ import ( "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/fungible/types" ) @@ -49,10 +49,10 @@ func TestMsgDeployFungibleCoinZRC4_ValidateBasic(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - assert.ErrorIs(t, err, tt.err) + require.ErrorIs(t, err, tt.err) return } - assert.NoError(t, err) + require.NoError(t, err) }) } } diff --git a/x/fungible/types/message_deploy_system_contracts_test.go b/x/fungible/types/message_deploy_system_contracts_test.go index ff4b7111fd..b14aa419ed 100644 --- a/x/fungible/types/message_deploy_system_contracts_test.go +++ b/x/fungible/types/message_deploy_system_contracts_test.go @@ -4,7 +4,7 @@ import ( "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/fungible/types" ) @@ -33,10 +33,10 @@ func TestMsgDeploySystemContract_ValidateBasic(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - assert.ErrorIs(t, err, tt.err) + require.ErrorIs(t, err, tt.err) return } - assert.NoError(t, err) + require.NoError(t, err) }) } } diff --git a/x/fungible/types/message_remove_foreign_coin_test.go b/x/fungible/types/message_remove_foreign_coin_test.go index b5949c722f..66a4c143f3 100644 --- a/x/fungible/types/message_remove_foreign_coin_test.go +++ b/x/fungible/types/message_remove_foreign_coin_test.go @@ -4,7 +4,7 @@ import ( "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/fungible/types" ) @@ -33,10 +33,10 @@ func TestMsgRemoveForeignCoin_ValidateBasic(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - assert.ErrorIs(t, err, tt.err) + require.ErrorIs(t, err, tt.err) return } - assert.NoError(t, err) + require.NoError(t, err) }) } } diff --git a/x/fungible/types/message_update_contract_bytecode_test.go b/x/fungible/types/message_update_contract_bytecode_test.go index 9e7d0970cd..02e8b3cfdd 100644 --- a/x/fungible/types/message_update_contract_bytecode_test.go +++ b/x/fungible/types/message_update_contract_bytecode_test.go @@ -3,7 +3,7 @@ package types_test import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/fungible/types" ) @@ -56,9 +56,9 @@ func TestMsgUpdateContractBytecode_ValidateBasic(t *testing.T) { t.Run(tc.name, func(t *testing.T) { err := tc.msg.ValidateBasic() if tc.wantError { - assert.Error(t, err) + require.Error(t, err) } else { - assert.NoError(t, err) + require.NoError(t, err) } }) } diff --git a/x/fungible/types/message_update_system_contract_test.go b/x/fungible/types/message_update_system_contract_test.go index 00ce59b4ab..8ee196ad39 100644 --- a/x/fungible/types/message_update_system_contract_test.go +++ b/x/fungible/types/message_update_system_contract_test.go @@ -4,7 +4,7 @@ import ( "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/fungible/types" ) @@ -43,10 +43,10 @@ func TestMsgUpdateSystemContract_ValidateBasic(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - assert.ErrorIs(t, err, tt.err) + require.ErrorIs(t, err, tt.err) return } - assert.NoError(t, err) + require.NoError(t, err) }) } } diff --git a/x/fungible/types/message_update_zrc20_liquidity_cap_test.go b/x/fungible/types/message_update_zrc20_liquidity_cap_test.go index f62193d63e..d59198ce39 100644 --- a/x/fungible/types/message_update_zrc20_liquidity_cap_test.go +++ b/x/fungible/types/message_update_zrc20_liquidity_cap_test.go @@ -6,7 +6,7 @@ import ( "cosmossdk.io/math" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/fungible/types" ) @@ -61,10 +61,10 @@ func TestNewMsgUpdateZRC20LiquidityCap_ValidateBasics(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - assert.ErrorIs(t, err, tt.err) + require.ErrorIs(t, err, tt.err) return } - assert.NoError(t, err) + require.NoError(t, err) }) } } diff --git a/x/fungible/types/message_update_zrc20_paused_status_test.go b/x/fungible/types/message_update_zrc20_paused_status_test.go index 40ddf7c3ae..326af3fe96 100644 --- a/x/fungible/types/message_update_zrc20_paused_status_test.go +++ b/x/fungible/types/message_update_zrc20_paused_status_test.go @@ -3,7 +3,7 @@ package types_test import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/fungible/types" ) @@ -94,9 +94,9 @@ func TestMMsgUpdateZRC20PausedStatus_ValidateBasic(t *testing.T) { t.Run(tc.name, func(t *testing.T) { err := tc.msg.ValidateBasic() if tc.wantErr { - assert.Error(t, err) + require.Error(t, err) } else { - assert.NoError(t, err) + require.NoError(t, err) } }) } diff --git a/x/fungible/types/message_update_zrc20_withdraw_fee_test.go b/x/fungible/types/message_update_zrc20_withdraw_fee_test.go index 232dae1a46..2aba73d42a 100644 --- a/x/fungible/types/message_update_zrc20_withdraw_fee_test.go +++ b/x/fungible/types/message_update_zrc20_withdraw_fee_test.go @@ -6,7 +6,7 @@ import ( math "cosmossdk.io/math" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/fungible/types" ) @@ -93,10 +93,10 @@ func TestMsgUpdateZRC20WithdrawFee_ValidateBasic(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - assert.ErrorIs(t, err, tt.err) + require.ErrorIs(t, err, tt.err) return } - assert.NoError(t, err) + require.NoError(t, err) }) } } diff --git a/x/observer/genesis_test.go b/x/observer/genesis_test.go index 853dc10996..56cc00352f 100644 --- a/x/observer/genesis_test.go +++ b/x/observer/genesis_test.go @@ -3,7 +3,7 @@ package observer_test import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/nullify" "github.com/zeta-chain/zetacore/testutil/sample" @@ -47,10 +47,10 @@ func TestGenesis(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) observer.InitGenesis(ctx, *k, genesisState) got := observer.ExportGenesis(ctx, *k) - assert.NotNil(t, got) + require.NotNil(t, got) // Compare genesis after init and export nullify.Fill(&genesisState) nullify.Fill(got) - assert.Equal(t, genesisState, *got) + require.Equal(t, genesisState, *got) } diff --git a/x/observer/keeper/chain_nonces_test.go b/x/observer/keeper/chain_nonces_test.go index 44118ecc5b..0c511d3f79 100644 --- a/x/observer/keeper/chain_nonces_test.go +++ b/x/observer/keeper/chain_nonces_test.go @@ -3,7 +3,7 @@ package keeper_test import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" ) @@ -17,8 +17,8 @@ func TestKeeper_GetChainNonces(t *testing.T) { } for _, n := range chainNoncesList { rst, found := k.GetChainNonces(ctx, n.Index) - assert.True(t, found) - assert.Equal(t, n, rst) + require.True(t, found) + require.Equal(t, n, rst) } }) t.Run("Get chain nonces not found", func(t *testing.T) { @@ -28,7 +28,7 @@ func TestKeeper_GetChainNonces(t *testing.T) { k.SetChainNonces(ctx, n) } _, found := k.GetChainNonces(ctx, "not_found") - assert.False(t, found) + require.False(t, found) }) t.Run("Get all chain nonces", func(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) @@ -37,6 +37,6 @@ func TestKeeper_GetChainNonces(t *testing.T) { k.SetChainNonces(ctx, n) } rst := k.GetAllChainNonces(ctx) - assert.Equal(t, chainNoncesList, rst) + require.Equal(t, chainNoncesList, rst) }) } diff --git a/x/observer/keeper/chain_params_test.go b/x/observer/keeper/chain_params_test.go index f5283c7feb..c9142b7526 100644 --- a/x/observer/keeper/chain_params_test.go +++ b/x/observer/keeper/chain_params_test.go @@ -3,7 +3,7 @@ package keeper_test import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -15,11 +15,11 @@ func TestKeeper_GetSupportedChainFromChainID(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) // no core params list - assert.Nil(t, k.GetSupportedChainFromChainID(ctx, getValidEthChainIDWithIndex(t, 0))) + require.Nil(t, k.GetSupportedChainFromChainID(ctx, getValidEthChainIDWithIndex(t, 0))) // core params list but chain not in list setSupportedChain(ctx, *k, getValidEthChainIDWithIndex(t, 0)) - assert.Nil(t, k.GetSupportedChainFromChainID(ctx, getValidEthChainIDWithIndex(t, 1))) + require.Nil(t, k.GetSupportedChainFromChainID(ctx, getValidEthChainIDWithIndex(t, 1))) // chain params list but chain not supported chainParams := sample.ChainParams(getValidEthChainIDWithIndex(t, 0)) @@ -27,7 +27,7 @@ func TestKeeper_GetSupportedChainFromChainID(t *testing.T) { k.SetChainParamsList(ctx, types.ChainParamsList{ ChainParams: []*types.ChainParams{chainParams}, }) - assert.Nil(t, k.GetSupportedChainFromChainID(ctx, getValidEthChainIDWithIndex(t, 0))) + require.Nil(t, k.GetSupportedChainFromChainID(ctx, getValidEthChainIDWithIndex(t, 0))) }) t.Run("return chain if chain found", func(t *testing.T) { @@ -35,21 +35,21 @@ func TestKeeper_GetSupportedChainFromChainID(t *testing.T) { chainID := getValidEthChainIDWithIndex(t, 0) setSupportedChain(ctx, *k, getValidEthChainIDWithIndex(t, 1), chainID) chain := k.GetSupportedChainFromChainID(ctx, chainID) - assert.NotNil(t, chain) - assert.EqualValues(t, chainID, chain.ChainId) + require.NotNil(t, chain) + require.EqualValues(t, chainID, chain.ChainId) }) } func TestKeeper_GetSupportedChains(t *testing.T) { t.Run("return empty list if no core params list", func(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) - assert.Empty(t, k.GetSupportedChains(ctx)) + require.Empty(t, k.GetSupportedChains(ctx)) }) t.Run("return list containing supported chains", func(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) - assert.Greater(t, len(common.ExternalChainList()), 5) + require.Greater(t, len(common.ExternalChainList()), 5) supported1 := common.ExternalChainList()[0] supported2 := common.ExternalChainList()[1] unsupported := common.ExternalChainList()[2] @@ -69,10 +69,10 @@ func TestKeeper_GetSupportedChains(t *testing.T) { supportedChains := k.GetSupportedChains(ctx) - assert.Len(t, supportedChains, 4) - assert.EqualValues(t, supported1.ChainId, supportedChains[0].ChainId) - assert.EqualValues(t, supported2.ChainId, supportedChains[1].ChainId) - assert.EqualValues(t, supported3.ChainId, supportedChains[2].ChainId) - assert.EqualValues(t, supported4.ChainId, supportedChains[3].ChainId) + require.Len(t, supportedChains, 4) + require.EqualValues(t, supported1.ChainId, supportedChains[0].ChainId) + require.EqualValues(t, supported2.ChainId, supportedChains[1].ChainId) + require.EqualValues(t, supported3.ChainId, supportedChains[2].ChainId) + require.EqualValues(t, supported4.ChainId, supportedChains[3].ChainId) }) } diff --git a/x/observer/keeper/grpc_query_blame_test.go b/x/observer/keeper/grpc_query_blame_test.go index 038a855305..8e66e3a2da 100644 --- a/x/observer/keeper/grpc_query_blame_test.go +++ b/x/observer/keeper/grpc_query_blame_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/cosmos/cosmos-sdk/types/query" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/observer/types" @@ -26,8 +26,8 @@ func TestKeeper_BlameByIdentifier(t *testing.T) { }) blameRecords, found := k.GetBlame(ctx, index) - assert.True(t, found) - assert.Equal(t, index, blameRecords.Index) + require.True(t, found) + require.Equal(t, index, blameRecords.Index) } func TestKeeper_BlameByChainAndNonce(t *testing.T) { @@ -45,9 +45,9 @@ func TestKeeper_BlameByChainAndNonce(t *testing.T) { }) blameRecords, found := k.GetBlamesByChainAndNonce(ctx, chainId, int64(nonce)) - assert.True(t, found) - assert.Equal(t, 1, len(blameRecords)) - assert.Equal(t, index, blameRecords[0].Index) + require.True(t, found) + require.Equal(t, 1, len(blameRecords)) + require.Equal(t, index, blameRecords[0].Index) } func TestKeeper_BlameAll(t *testing.T) { @@ -61,12 +61,12 @@ func TestKeeper_BlameAll(t *testing.T) { return blameList[i].Index < blameList[j].Index }) rst, pageRes, err := k.GetAllBlamePaginated(ctx, &query.PageRequest{Limit: 10, CountTotal: true}) - assert.NoError(t, err) + require.NoError(t, err) sort.Slice(rst, func(i, j int) bool { return rst[i].Index < rst[j].Index }) - assert.Equal(t, blameList, rst) - assert.Equal(t, len(blameList), int(pageRes.Total)) + require.Equal(t, blameList, rst) + require.Equal(t, len(blameList), int(pageRes.Total)) }) t.Run("GetBlameRecord by offset ", func(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) @@ -79,13 +79,13 @@ func TestKeeper_BlameAll(t *testing.T) { return blameList[i].Index < blameList[j].Index }) rst, pageRes, err := k.GetAllBlamePaginated(ctx, &query.PageRequest{Offset: uint64(offset), CountTotal: true}) - assert.NoError(t, err) + require.NoError(t, err) sort.Slice(rst, func(i, j int) bool { return rst[i].Index < rst[j].Index }) - assert.Subset(t, blameList, rst) - assert.Equal(t, len(blameList)-offset, len(rst)) - assert.Equal(t, len(blameList), int(pageRes.Total)) + require.Subset(t, blameList, rst) + require.Equal(t, len(blameList)-offset, len(rst)) + require.Equal(t, len(blameList), int(pageRes.Total)) }) t.Run("GetAllBlameRecord", func(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) @@ -100,11 +100,11 @@ func TestKeeper_BlameAll(t *testing.T) { sort.Slice(blameList, func(i, j int) bool { return blameList[i].Index < blameList[j].Index }) - assert.Equal(t, blameList, rst) + require.Equal(t, blameList, rst) }) t.Run("Get no records if nothing is set", func(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) rst := k.GetAllBlame(ctx) - assert.Len(t, rst, 0) + require.Len(t, rst, 0) }) } diff --git a/x/observer/keeper/grpc_query_keygen_test.go b/x/observer/keeper/grpc_query_keygen_test.go index 27c90a0c3a..f4c61aeabd 100644 --- a/x/observer/keeper/grpc_query_keygen_test.go +++ b/x/observer/keeper/grpc_query_keygen_test.go @@ -1,7 +1,7 @@ package keeper import ( - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "testing" @@ -29,9 +29,9 @@ func TestKeygenQuery(t *testing.T) { t.Run(tc.desc, func(t *testing.T) { response, err := keeper.Keygen(wctx, tc.request) if tc.err != nil { - assert.ErrorIs(t, err, tc.err) + require.ErrorIs(t, err, tc.err) } else { - assert.Equal(t, tc.response, response) + require.Equal(t, tc.response, response) } }) } diff --git a/x/observer/keeper/grpc_query_node_account_test.go b/x/observer/keeper/grpc_query_node_account_test.go index 3b36749b31..03facb08b4 100644 --- a/x/observer/keeper/grpc_query_node_account_test.go +++ b/x/observer/keeper/grpc_query_node_account_test.go @@ -5,7 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/x/observer/types" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -45,9 +45,9 @@ func TestNodeAccountQuerySingle(t *testing.T) { t.Run(tc.desc, func(t *testing.T) { response, err := keeper.NodeAccount(wctx, tc.request) if tc.err != nil { - assert.ErrorIs(t, err, tc.err) + require.ErrorIs(t, err, tc.err) } else { - assert.Equal(t, tc.response, response) + require.Equal(t, tc.response, response) } }) } @@ -72,9 +72,9 @@ func TestNodeAccountQueryPaginated(t *testing.T) { step := 2 for i := 0; i < len(msgs); i += step { resp, err := keeper.NodeAccountAll(wctx, request(nil, uint64(i), uint64(step), false)) - assert.NoError(t, err) + require.NoError(t, err) for j := i; j < len(msgs) && j < i+step; j++ { - assert.Equal(t, &msgs[j], resp.NodeAccount[j-i]) + require.Equal(t, &msgs[j], resp.NodeAccount[j-i]) } } }) @@ -83,20 +83,20 @@ func TestNodeAccountQueryPaginated(t *testing.T) { var next []byte for i := 0; i < len(msgs); i += step { resp, err := keeper.NodeAccountAll(wctx, request(next, 0, uint64(step), false)) - assert.NoError(t, err) + require.NoError(t, err) for j := i; j < len(msgs) && j < i+step; j++ { - assert.Equal(t, &msgs[j], resp.NodeAccount[j-i]) + require.Equal(t, &msgs[j], resp.NodeAccount[j-i]) } next = resp.Pagination.NextKey } }) t.Run("Total", func(t *testing.T) { resp, err := keeper.NodeAccountAll(wctx, request(nil, 0, 0, true)) - assert.NoError(t, err) - assert.Equal(t, len(msgs), int(resp.Pagination.Total)) + require.NoError(t, err) + require.Equal(t, len(msgs), int(resp.Pagination.Total)) }) t.Run("InvalidRequest", func(t *testing.T) { _, err := keeper.NodeAccountAll(wctx, nil) - assert.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) + require.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) }) } diff --git a/x/observer/keeper/grpc_query_nonces_test.go b/x/observer/keeper/grpc_query_nonces_test.go index 809220e4c7..6ec06efd28 100644 --- a/x/observer/keeper/grpc_query_nonces_test.go +++ b/x/observer/keeper/grpc_query_nonces_test.go @@ -5,7 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/query" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/observer/types" @@ -50,9 +50,9 @@ func TestChainNoncesQuerySingle(t *testing.T) { t.Run(tc.desc, func(t *testing.T) { response, err := k.ChainNonces(wctx, tc.request) if tc.err != nil { - assert.ErrorIs(t, err, tc.err) + require.ErrorIs(t, err, tc.err) } else { - assert.Equal(t, tc.response, response) + require.Equal(t, tc.response, response) } }) } @@ -80,9 +80,9 @@ func TestChainNoncesQueryPaginated(t *testing.T) { step := 2 for i := 0; i < len(chainNonces); i += step { resp, err := k.ChainNoncesAll(wctx, request(nil, uint64(i), uint64(step), false)) - assert.NoError(t, err) + require.NoError(t, err) for j := i; j < len(chainNonces) && j < i+step; j++ { - assert.Equal(t, chainNonces[j], resp.ChainNonces[j-i]) + require.Equal(t, chainNonces[j], resp.ChainNonces[j-i]) } } }) @@ -91,20 +91,20 @@ func TestChainNoncesQueryPaginated(t *testing.T) { var next []byte for i := 0; i < len(chainNonces); i += step { resp, err := k.ChainNoncesAll(wctx, request(next, 0, uint64(step), false)) - assert.NoError(t, err) + require.NoError(t, err) for j := i; j < len(chainNonces) && j < i+step; j++ { - assert.Equal(t, chainNonces[j], resp.ChainNonces[j-i]) + require.Equal(t, chainNonces[j], resp.ChainNonces[j-i]) } next = resp.Pagination.NextKey } }) t.Run("Total", func(t *testing.T) { resp, err := k.ChainNoncesAll(wctx, request(nil, 0, 0, true)) - assert.NoError(t, err) - assert.Equal(t, len(chainNonces), int(resp.Pagination.Total)) + require.NoError(t, err) + require.Equal(t, len(chainNonces), int(resp.Pagination.Total)) }) t.Run("InvalidRequest", func(t *testing.T) { _, err := k.ChainNoncesAll(wctx, nil) - assert.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) + require.ErrorIs(t, err, status.Error(codes.InvalidArgument, "invalid request")) }) } diff --git a/x/observer/keeper/grpc_query_params_test.go b/x/observer/keeper/grpc_query_params_test.go index 3eaf8963f0..4cd534fa59 100644 --- a/x/observer/keeper/grpc_query_params_test.go +++ b/x/observer/keeper/grpc_query_params_test.go @@ -4,7 +4,7 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/x/observer/types" ) @@ -15,6 +15,6 @@ func TestParamsQuery(t *testing.T) { keeper.SetParams(ctx, params) response, err := keeper.Params(wctx, &types.QueryParamsRequest{}) - assert.NoError(t, err) - assert.Equal(t, &types.QueryParamsResponse{Params: params}, response) + require.NoError(t, err) + require.Equal(t, &types.QueryParamsResponse{Params: params}, response) } diff --git a/x/observer/keeper/keeper_test.go b/x/observer/keeper/keeper_test.go index 41ad55a8d0..7c13b7b0f2 100644 --- a/x/observer/keeper/keeper_test.go +++ b/x/observer/keeper/keeper_test.go @@ -12,7 +12,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" typesparams "github.com/cosmos/cosmos-sdk/x/params/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmdb "github.com/tendermint/tm-db" "github.com/zeta-chain/zetacore/x/observer/types" @@ -26,7 +26,7 @@ func SetupKeeper(t testing.TB) (*Keeper, sdk.Context) { stateStore := store.NewCommitMultiStore(db) stateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, db) stateStore.MountStoreWithDB(memStoreKey, storetypes.StoreTypeMemory, nil) - assert.NoError(t, stateStore.LoadLatestVersion()) + require.NoError(t, stateStore.LoadLatestVersion()) registry := codectypes.NewInterfaceRegistry() cdc := codec.NewProtoCodec(registry) diff --git a/x/observer/keeper/keygen_test.go b/x/observer/keeper/keygen_test.go index a48c769c37..f14fa3aeef 100644 --- a/x/observer/keeper/keygen_test.go +++ b/x/observer/keeper/keygen_test.go @@ -4,7 +4,7 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/x/observer/types" ) @@ -22,13 +22,13 @@ func TestKeygenGet(t *testing.T) { keeper, ctx := SetupKeeper(t) item := createTestKeygen(keeper, ctx) rst, found := keeper.GetKeygen(ctx) - assert.True(t, found) - assert.Equal(t, item, rst) + require.True(t, found) + require.Equal(t, item, rst) } func TestKeygenRemove(t *testing.T) { keeper, ctx := SetupKeeper(t) createTestKeygen(keeper, ctx) keeper.RemoveKeygen(ctx) _, found := keeper.GetKeygen(ctx) - assert.False(t, found) + require.False(t, found) } diff --git a/x/observer/keeper/msg_server_add_block_header_test.go b/x/observer/keeper/msg_server_add_block_header_test.go index 3d9f35b446..34bde9c115 100644 --- a/x/observer/keeper/msg_server_add_block_header_test.go +++ b/x/observer/keeper/msg_server_add_block_header_test.go @@ -6,7 +6,7 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/ethereum/go-ethereum/rlp" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -16,19 +16,19 @@ import ( func TestMsgServer_AddBlockHeader(t *testing.T) { header, header2, header3, err := sample.EthHeader() - assert.NoError(t, err) + require.NoError(t, err) header1RLP, err := rlp.EncodeToBytes(header) - assert.NoError(t, err) + require.NoError(t, err) header2RLP, err := rlp.EncodeToBytes(header2) _ = header2RLP - assert.NoError(t, err) + require.NoError(t, err) header3RLP, err := rlp.EncodeToBytes(header3) - assert.NoError(t, err) + require.NoError(t, err) r := rand.New(rand.NewSource(9)) validator := sample.Validator(t, r) observerAddress, err := types.GetAccAddressFromOperatorAddress(validator.OperatorAddress) - assert.NoError(t, err) + require.NoError(t, err) // Add tests for btc headers : https://github.com/zeta-chain/node/issues/1336 tt := []struct { name string @@ -36,7 +36,7 @@ func TestMsgServer_AddBlockHeader(t *testing.T) { IsEthTypeChainEnabled bool IsBtcTypeChainEnabled bool validator stakingtypes.Validator - wantErr assert.ErrorAssertionFunc + wantErr require.ErrorAssertionFunc }{ { name: "success submit eth header", @@ -50,7 +50,7 @@ func TestMsgServer_AddBlockHeader(t *testing.T) { IsEthTypeChainEnabled: true, IsBtcTypeChainEnabled: true, validator: validator, - wantErr: assert.NoError, + wantErr: require.NoError, }, { name: "failure submit eth header eth disabled", @@ -64,8 +64,8 @@ func TestMsgServer_AddBlockHeader(t *testing.T) { IsEthTypeChainEnabled: false, IsBtcTypeChainEnabled: true, validator: validator, - wantErr: func(t assert.TestingT, err error, i ...interface{}) bool { - return assert.ErrorIs(t, err, types.ErrBlockHeaderVerificationDisabled) + wantErr: func(t require.TestingT, err error, i ...interface{}) { + require.ErrorIs(t, err, types.ErrBlockHeaderVerificationDisabled) }, }, { @@ -80,8 +80,8 @@ func TestMsgServer_AddBlockHeader(t *testing.T) { IsEthTypeChainEnabled: false, IsBtcTypeChainEnabled: true, validator: validator, - wantErr: func(t assert.TestingT, err error, i ...interface{}) bool { - return assert.ErrorIs(t, err, types.ErrNotAuthorizedPolicy) + wantErr: func(t require.TestingT, err error, i ...interface{}) { + require.ErrorIs(t, err, types.ErrNotAuthorizedPolicy) }, }, { @@ -96,8 +96,8 @@ func TestMsgServer_AddBlockHeader(t *testing.T) { IsEthTypeChainEnabled: true, IsBtcTypeChainEnabled: true, validator: validator, - wantErr: func(t assert.TestingT, err error, i ...interface{}) bool { - return assert.Error(t, err) + wantErr: func(t require.TestingT, err error, i ...interface{}) { + require.Error(t, err) }, }, { @@ -112,7 +112,7 @@ func TestMsgServer_AddBlockHeader(t *testing.T) { IsEthTypeChainEnabled: true, IsBtcTypeChainEnabled: true, validator: validator, - wantErr: assert.NoError, + wantErr: require.NoError, }, { name: "should succeed to post 3rd header if 2nd header is posted", @@ -126,8 +126,8 @@ func TestMsgServer_AddBlockHeader(t *testing.T) { IsEthTypeChainEnabled: true, IsBtcTypeChainEnabled: true, validator: validator, - wantErr: func(t assert.TestingT, err error, i ...interface{}) bool { - return assert.Error(t, err) + wantErr: func(t require.TestingT, err error, i ...interface{}) { + require.Error(t, err) }, }, { @@ -142,8 +142,8 @@ func TestMsgServer_AddBlockHeader(t *testing.T) { IsEthTypeChainEnabled: true, IsBtcTypeChainEnabled: true, validator: validator, - wantErr: func(t assert.TestingT, err error, i ...interface{}) bool { - return assert.ErrorIs(t, err, types.ErrSupportedChains) + wantErr: func(t require.TestingT, err error, i ...interface{}) { + require.ErrorIs(t, err, types.ErrSupportedChains) }, }, } @@ -171,8 +171,8 @@ func TestMsgServer_AddBlockHeader(t *testing.T) { tc.wantErr(t, err) if err == nil { bhs, found := k.GetBlockHeaderState(ctx, tc.msg.ChainId) - assert.True(t, found) - assert.Equal(t, tc.msg.Height, bhs.LatestHeight) + require.True(t, found) + require.Equal(t, tc.msg.Height, bhs.LatestHeight) } }) } diff --git a/x/observer/keeper/msg_server_remove_chain_params_test.go b/x/observer/keeper/msg_server_remove_chain_params_test.go index 15a089ab3f..d99b301403 100644 --- a/x/observer/keeper/msg_server_remove_chain_params_test.go +++ b/x/observer/keeper/msg_server_remove_chain_params_test.go @@ -4,7 +4,7 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -39,39 +39,39 @@ func TestMsgServer_RemoveChainParams(t *testing.T) { Creator: admin, ChainId: chain2, }) - assert.NoError(t, err) + require.NoError(t, err) // check list has two chain params chainParamsList, found := k.GetChainParamsList(ctx) - assert.True(t, found) - assert.Len(t, chainParamsList.ChainParams, 2) - assert.Equal(t, chain1, chainParamsList.ChainParams[0].ChainId) - assert.Equal(t, chain3, chainParamsList.ChainParams[1].ChainId) + require.True(t, found) + require.Len(t, chainParamsList.ChainParams, 2) + require.Equal(t, chain1, chainParamsList.ChainParams[0].ChainId) + require.Equal(t, chain3, chainParamsList.ChainParams[1].ChainId) // remove chain params _, err = srv.RemoveChainParams(sdk.WrapSDKContext(ctx), &types.MsgRemoveChainParams{ Creator: admin, ChainId: chain1, }) - assert.NoError(t, err) + require.NoError(t, err) // check list has one chain params chainParamsList, found = k.GetChainParamsList(ctx) - assert.True(t, found) - assert.Len(t, chainParamsList.ChainParams, 1) - assert.Equal(t, chain3, chainParamsList.ChainParams[0].ChainId) + require.True(t, found) + require.Len(t, chainParamsList.ChainParams, 1) + require.Equal(t, chain3, chainParamsList.ChainParams[0].ChainId) // remove chain params _, err = srv.RemoveChainParams(sdk.WrapSDKContext(ctx), &types.MsgRemoveChainParams{ Creator: admin, ChainId: chain3, }) - assert.NoError(t, err) + require.NoError(t, err) // check list has no chain params chainParamsList, found = k.GetChainParamsList(ctx) - assert.True(t, found) - assert.Len(t, chainParamsList.ChainParams, 0) + require.True(t, found) + require.Len(t, chainParamsList.ChainParams, 0) }) t.Run("cannot remove chain params if not authorized", func(t *testing.T) { @@ -82,7 +82,7 @@ func TestMsgServer_RemoveChainParams(t *testing.T) { Creator: sample.AccAddress(), ChainParams: sample.ChainParams(common.ExternalChainList()[0].ChainId), }) - assert.ErrorIs(t, err, types.ErrNotAuthorizedPolicy) + require.ErrorIs(t, err, types.ErrNotAuthorizedPolicy) // group 1 should not be able to update core params admin := sample.AccAddress() @@ -92,7 +92,7 @@ func TestMsgServer_RemoveChainParams(t *testing.T) { Creator: sample.AccAddress(), ChainParams: sample.ChainParams(common.ExternalChainList()[0].ChainId), }) - assert.ErrorIs(t, err, types.ErrNotAuthorizedPolicy) + require.ErrorIs(t, err, types.ErrNotAuthorizedPolicy) }) @@ -106,13 +106,13 @@ func TestMsgServer_RemoveChainParams(t *testing.T) { // not found if no chain params _, found := k.GetChainParamsList(ctx) - assert.False(t, found) + require.False(t, found) _, err := srv.RemoveChainParams(sdk.WrapSDKContext(ctx), &types.MsgRemoveChainParams{ Creator: admin, ChainId: common.ExternalChainList()[0].ChainId, }) - assert.ErrorIs(t, err, types.ErrChainParamsNotFound) + require.ErrorIs(t, err, types.ErrChainParamsNotFound) // add chain params k.SetChainParamsList(ctx, types.ChainParamsList{ @@ -128,6 +128,6 @@ func TestMsgServer_RemoveChainParams(t *testing.T) { Creator: admin, ChainId: common.ExternalChainList()[3].ChainId, }) - assert.ErrorIs(t, err, types.ErrChainParamsNotFound) + require.ErrorIs(t, err, types.ErrChainParamsNotFound) }) } diff --git a/x/observer/keeper/msg_server_update_chain_params_test.go b/x/observer/keeper/msg_server_update_chain_params_test.go index 8d8680c919..7b2f8a5cb3 100644 --- a/x/observer/keeper/msg_server_update_chain_params_test.go +++ b/x/observer/keeper/msg_server_update_chain_params_test.go @@ -4,7 +4,7 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -27,7 +27,7 @@ func TestMsgServer_UpdateChainParams(t *testing.T) { // check list initially empty _, found := k.GetChainParamsList(ctx) - assert.False(t, found) + require.False(t, found) // a new chain params can be added chainParams1 := sample.ChainParams(chain1) @@ -35,13 +35,13 @@ func TestMsgServer_UpdateChainParams(t *testing.T) { Creator: admin, ChainParams: chainParams1, }) - assert.NoError(t, err) + require.NoError(t, err) // check list has one chain params chainParamsList, found := k.GetChainParamsList(ctx) - assert.True(t, found) - assert.Len(t, chainParamsList.ChainParams, 1) - assert.Equal(t, chainParams1, chainParamsList.ChainParams[0]) + require.True(t, found) + require.Len(t, chainParamsList.ChainParams, 1) + require.Equal(t, chainParams1, chainParamsList.ChainParams[0]) // a new chian params can be added chainParams2 := sample.ChainParams(chain2) @@ -49,14 +49,14 @@ func TestMsgServer_UpdateChainParams(t *testing.T) { Creator: admin, ChainParams: chainParams2, }) - assert.NoError(t, err) + require.NoError(t, err) // check list has two chain params chainParamsList, found = k.GetChainParamsList(ctx) - assert.True(t, found) - assert.Len(t, chainParamsList.ChainParams, 2) - assert.Equal(t, chainParams1, chainParamsList.ChainParams[0]) - assert.Equal(t, chainParams2, chainParamsList.ChainParams[1]) + require.True(t, found) + require.Len(t, chainParamsList.ChainParams, 2) + require.Equal(t, chainParams1, chainParamsList.ChainParams[0]) + require.Equal(t, chainParams2, chainParamsList.ChainParams[1]) // a new chain params can be added chainParams3 := sample.ChainParams(chain3) @@ -64,15 +64,15 @@ func TestMsgServer_UpdateChainParams(t *testing.T) { Creator: admin, ChainParams: chainParams3, }) - assert.NoError(t, err) + require.NoError(t, err) // check list has three chain params chainParamsList, found = k.GetChainParamsList(ctx) - assert.True(t, found) - assert.Len(t, chainParamsList.ChainParams, 3) - assert.Equal(t, chainParams1, chainParamsList.ChainParams[0]) - assert.Equal(t, chainParams2, chainParamsList.ChainParams[1]) - assert.Equal(t, chainParams3, chainParamsList.ChainParams[2]) + require.True(t, found) + require.Len(t, chainParamsList.ChainParams, 3) + require.Equal(t, chainParams1, chainParamsList.ChainParams[0]) + require.Equal(t, chainParams2, chainParamsList.ChainParams[1]) + require.Equal(t, chainParams3, chainParamsList.ChainParams[2]) // chain params can be updated chainParams2.ConfirmationCount = chainParams2.ConfirmationCount + 1 @@ -80,15 +80,15 @@ func TestMsgServer_UpdateChainParams(t *testing.T) { Creator: admin, ChainParams: chainParams2, }) - assert.NoError(t, err) + require.NoError(t, err) // check list has three chain params chainParamsList, found = k.GetChainParamsList(ctx) - assert.True(t, found) - assert.Len(t, chainParamsList.ChainParams, 3) - assert.Equal(t, chainParams1, chainParamsList.ChainParams[0]) - assert.Equal(t, chainParams2, chainParamsList.ChainParams[1]) - assert.Equal(t, chainParams3, chainParamsList.ChainParams[2]) + require.True(t, found) + require.Len(t, chainParamsList.ChainParams, 3) + require.Equal(t, chainParams1, chainParamsList.ChainParams[0]) + require.Equal(t, chainParams2, chainParamsList.ChainParams[1]) + require.Equal(t, chainParams3, chainParamsList.ChainParams[2]) }) t.Run("cannot update chain params if not authorized", func(t *testing.T) { @@ -99,7 +99,7 @@ func TestMsgServer_UpdateChainParams(t *testing.T) { Creator: sample.AccAddress(), ChainParams: sample.ChainParams(common.ExternalChainList()[0].ChainId), }) - assert.ErrorIs(t, err, types.ErrNotAuthorizedPolicy) + require.ErrorIs(t, err, types.ErrNotAuthorizedPolicy) // group 1 should not be able to update chain params admin := sample.AccAddress() @@ -109,7 +109,7 @@ func TestMsgServer_UpdateChainParams(t *testing.T) { Creator: sample.AccAddress(), ChainParams: sample.ChainParams(common.ExternalChainList()[0].ChainId), }) - assert.ErrorIs(t, err, types.ErrNotAuthorizedPolicy) + require.ErrorIs(t, err, types.ErrNotAuthorizedPolicy) }) } diff --git a/x/observer/keeper/msg_server_update_crosschain_flags_test.go b/x/observer/keeper/msg_server_update_crosschain_flags_test.go index 79654d6ed3..555988694c 100644 --- a/x/observer/keeper/msg_server_update_crosschain_flags_test.go +++ b/x/observer/keeper/msg_server_update_crosschain_flags_test.go @@ -5,7 +5,7 @@ import ( "time" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/observer/keeper" @@ -46,17 +46,17 @@ func TestMsgServer_UpdateCrosschainFlags(t *testing.T) { IsBtcTypeChainEnabled: false, }, }) - assert.NoError(t, err) + require.NoError(t, err) flags, found := k.GetCrosschainFlags(ctx) - assert.True(t, found) - assert.False(t, flags.IsInboundEnabled) - assert.False(t, flags.IsOutboundEnabled) - assert.Equal(t, int64(42), flags.GasPriceIncreaseFlags.EpochLength) - assert.Equal(t, time.Minute*42, flags.GasPriceIncreaseFlags.RetryInterval) - assert.Equal(t, uint32(42), flags.GasPriceIncreaseFlags.GasPriceIncreasePercent) - assert.True(t, flags.BlockHeaderVerificationFlags.IsEthTypeChainEnabled) - assert.False(t, flags.BlockHeaderVerificationFlags.IsBtcTypeChainEnabled) + require.True(t, found) + require.False(t, flags.IsInboundEnabled) + require.False(t, flags.IsOutboundEnabled) + require.Equal(t, int64(42), flags.GasPriceIncreaseFlags.EpochLength) + require.Equal(t, time.Minute*42, flags.GasPriceIncreaseFlags.RetryInterval) + require.Equal(t, uint32(42), flags.GasPriceIncreaseFlags.GasPriceIncreasePercent) + require.True(t, flags.BlockHeaderVerificationFlags.IsEthTypeChainEnabled) + require.False(t, flags.BlockHeaderVerificationFlags.IsBtcTypeChainEnabled) setAdminCrossChainFlags(ctx, k, admin, types.Policy_Type_group2) @@ -75,17 +75,17 @@ func TestMsgServer_UpdateCrosschainFlags(t *testing.T) { IsBtcTypeChainEnabled: true, }, }) - assert.NoError(t, err) + require.NoError(t, err) flags, found = k.GetCrosschainFlags(ctx) - assert.True(t, found) - assert.True(t, flags.IsInboundEnabled) - assert.True(t, flags.IsOutboundEnabled) - assert.Equal(t, int64(43), flags.GasPriceIncreaseFlags.EpochLength) - assert.Equal(t, time.Minute*43, flags.GasPriceIncreaseFlags.RetryInterval) - assert.Equal(t, uint32(43), flags.GasPriceIncreaseFlags.GasPriceIncreasePercent) - assert.False(t, flags.BlockHeaderVerificationFlags.IsEthTypeChainEnabled) - assert.True(t, flags.BlockHeaderVerificationFlags.IsBtcTypeChainEnabled) + require.True(t, found) + require.True(t, flags.IsInboundEnabled) + require.True(t, flags.IsOutboundEnabled) + require.Equal(t, int64(43), flags.GasPriceIncreaseFlags.EpochLength) + require.Equal(t, time.Minute*43, flags.GasPriceIncreaseFlags.RetryInterval) + require.Equal(t, uint32(43), flags.GasPriceIncreaseFlags.GasPriceIncreasePercent) + require.False(t, flags.BlockHeaderVerificationFlags.IsEthTypeChainEnabled) + require.True(t, flags.BlockHeaderVerificationFlags.IsBtcTypeChainEnabled) // group 1 should be able to disable inbound and outbound setAdminCrossChainFlags(ctx, k, admin, types.Policy_Type_group1) @@ -96,17 +96,17 @@ func TestMsgServer_UpdateCrosschainFlags(t *testing.T) { IsInboundEnabled: false, IsOutboundEnabled: false, }) - assert.NoError(t, err) + require.NoError(t, err) flags, found = k.GetCrosschainFlags(ctx) - assert.True(t, found) - assert.False(t, flags.IsInboundEnabled) - assert.False(t, flags.IsOutboundEnabled) - assert.Equal(t, int64(43), flags.GasPriceIncreaseFlags.EpochLength) - assert.Equal(t, time.Minute*43, flags.GasPriceIncreaseFlags.RetryInterval) - assert.Equal(t, uint32(43), flags.GasPriceIncreaseFlags.GasPriceIncreasePercent) - assert.False(t, flags.BlockHeaderVerificationFlags.IsEthTypeChainEnabled) - assert.True(t, flags.BlockHeaderVerificationFlags.IsBtcTypeChainEnabled) + require.True(t, found) + require.False(t, flags.IsInboundEnabled) + require.False(t, flags.IsOutboundEnabled) + require.Equal(t, int64(43), flags.GasPriceIncreaseFlags.EpochLength) + require.Equal(t, time.Minute*43, flags.GasPriceIncreaseFlags.RetryInterval) + require.Equal(t, uint32(43), flags.GasPriceIncreaseFlags.GasPriceIncreasePercent) + require.False(t, flags.BlockHeaderVerificationFlags.IsEthTypeChainEnabled) + require.True(t, flags.BlockHeaderVerificationFlags.IsBtcTypeChainEnabled) // group 1 should be able to disable header verification setAdminCrossChainFlags(ctx, k, admin, types.Policy_Type_group1) @@ -121,22 +121,22 @@ func TestMsgServer_UpdateCrosschainFlags(t *testing.T) { IsBtcTypeChainEnabled: false, }, }) - assert.NoError(t, err) + require.NoError(t, err) flags, found = k.GetCrosschainFlags(ctx) - assert.True(t, found) - assert.False(t, flags.IsInboundEnabled) - assert.False(t, flags.IsOutboundEnabled) - assert.Equal(t, int64(43), flags.GasPriceIncreaseFlags.EpochLength) - assert.Equal(t, time.Minute*43, flags.GasPriceIncreaseFlags.RetryInterval) - assert.Equal(t, uint32(43), flags.GasPriceIncreaseFlags.GasPriceIncreasePercent) - assert.False(t, flags.BlockHeaderVerificationFlags.IsEthTypeChainEnabled) - assert.False(t, flags.BlockHeaderVerificationFlags.IsBtcTypeChainEnabled) + require.True(t, found) + require.False(t, flags.IsInboundEnabled) + require.False(t, flags.IsOutboundEnabled) + require.Equal(t, int64(43), flags.GasPriceIncreaseFlags.EpochLength) + require.Equal(t, time.Minute*43, flags.GasPriceIncreaseFlags.RetryInterval) + require.Equal(t, uint32(43), flags.GasPriceIncreaseFlags.GasPriceIncreasePercent) + require.False(t, flags.BlockHeaderVerificationFlags.IsEthTypeChainEnabled) + require.False(t, flags.BlockHeaderVerificationFlags.IsBtcTypeChainEnabled) // if flags are not defined, default should be used k.RemoveCrosschainFlags(ctx) _, found = k.GetCrosschainFlags(ctx) - assert.False(t, found) + require.False(t, found) setAdminCrossChainFlags(ctx, k, admin, types.Policy_Type_group2) @@ -145,15 +145,15 @@ func TestMsgServer_UpdateCrosschainFlags(t *testing.T) { IsInboundEnabled: false, IsOutboundEnabled: true, }) - assert.NoError(t, err) + require.NoError(t, err) flags, found = k.GetCrosschainFlags(ctx) - assert.True(t, found) - assert.False(t, flags.IsInboundEnabled) - assert.True(t, flags.IsOutboundEnabled) - assert.Equal(t, types.DefaultGasPriceIncreaseFlags.EpochLength, flags.GasPriceIncreaseFlags.EpochLength) - assert.Equal(t, types.DefaultGasPriceIncreaseFlags.RetryInterval, flags.GasPriceIncreaseFlags.RetryInterval) - assert.Equal(t, types.DefaultGasPriceIncreaseFlags.GasPriceIncreasePercent, flags.GasPriceIncreaseFlags.GasPriceIncreasePercent) + require.True(t, found) + require.False(t, flags.IsInboundEnabled) + require.True(t, flags.IsOutboundEnabled) + require.Equal(t, types.DefaultGasPriceIncreaseFlags.EpochLength, flags.GasPriceIncreaseFlags.EpochLength) + require.Equal(t, types.DefaultGasPriceIncreaseFlags.RetryInterval, flags.GasPriceIncreaseFlags.RetryInterval) + require.Equal(t, types.DefaultGasPriceIncreaseFlags.GasPriceIncreasePercent, flags.GasPriceIncreaseFlags.GasPriceIncreasePercent) }) t.Run("cannot update crosschain flags if not authorized", func(t *testing.T) { @@ -165,8 +165,8 @@ func TestMsgServer_UpdateCrosschainFlags(t *testing.T) { IsInboundEnabled: false, IsOutboundEnabled: false, }) - assert.Error(t, err) - assert.Equal(t, types.ErrNotAuthorizedPolicy, err) + require.Error(t, err) + require.Equal(t, types.ErrNotAuthorizedPolicy, err) admin := sample.AccAddress() setAdminCrossChainFlags(ctx, k, admin, types.Policy_Type_group1) @@ -176,7 +176,7 @@ func TestMsgServer_UpdateCrosschainFlags(t *testing.T) { IsInboundEnabled: false, IsOutboundEnabled: true, }) - assert.Error(t, err) - assert.Equal(t, types.ErrNotAuthorizedPolicy, err) + require.Error(t, err) + require.Equal(t, types.ErrNotAuthorizedPolicy, err) }) } diff --git a/x/observer/keeper/msg_server_update_observer_test.go b/x/observer/keeper/msg_server_update_observer_test.go index 649ce6ca13..7fe73734d8 100644 --- a/x/observer/keeper/msg_server_update_observer_test.go +++ b/x/observer/keeper/msg_server_update_observer_test.go @@ -8,7 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/observer/keeper" @@ -30,7 +30,7 @@ func TestMsgServer_UpdateObserver(t *testing.T) { k.GetStakingKeeper().SetValidator(ctx, validator) consAddress, err := validator.GetConsAddr() - assert.NoError(t, err) + require.NoError(t, err) k.GetSlashingKeeper().SetValidatorSigningInfo(ctx, consAddress, slashingtypes.ValidatorSigningInfo{ Address: consAddress.String(), StartHeight: 0, @@ -40,10 +40,10 @@ func TestMsgServer_UpdateObserver(t *testing.T) { }) accAddressOfValidator, err := types.GetAccAddressFromOperatorAddress(validator.OperatorAddress) - assert.NoError(t, err) + require.NoError(t, err) newOperatorAddress, err := types.GetAccAddressFromOperatorAddress(validatorNew.OperatorAddress) - assert.NoError(t, err) + require.NoError(t, err) count := uint64(0) @@ -66,10 +66,10 @@ func TestMsgServer_UpdateObserver(t *testing.T) { NewObserverAddress: newOperatorAddress.String(), UpdateReason: types.ObserverUpdateReason_Tombstoned, }) - assert.NoError(t, err) + require.NoError(t, err) acc, found := k.GetNodeAccount(ctx, newOperatorAddress.String()) - assert.True(t, found) - assert.Equal(t, newOperatorAddress.String(), acc.Operator) + require.True(t, found) + require.Equal(t, newOperatorAddress.String(), acc.Operator) }) t.Run("unable to update to a non validator address", func(t *testing.T) { @@ -84,7 +84,7 @@ func TestMsgServer_UpdateObserver(t *testing.T) { k.GetStakingKeeper().SetValidator(ctx, validator) consAddress, err := validator.GetConsAddr() - assert.NoError(t, err) + require.NoError(t, err) k.GetSlashingKeeper().SetValidatorSigningInfo(ctx, consAddress, slashingtypes.ValidatorSigningInfo{ Address: consAddress.String(), StartHeight: 0, @@ -94,10 +94,10 @@ func TestMsgServer_UpdateObserver(t *testing.T) { }) accAddressOfValidator, err := types.GetAccAddressFromOperatorAddress(validator.OperatorAddress) - assert.NoError(t, err) + require.NoError(t, err) newOperatorAddress, err := types.GetAccAddressFromOperatorAddress(validatorNew.OperatorAddress) - assert.NoError(t, err) + require.NoError(t, err) count := uint64(0) k.SetObserverSet(ctx, types.ObserverSet{ @@ -118,7 +118,7 @@ func TestMsgServer_UpdateObserver(t *testing.T) { NewObserverAddress: newOperatorAddress.String(), UpdateReason: types.ObserverUpdateReason_Tombstoned, }) - assert.ErrorIs(t, err, types.ErrUpdateObserver) + require.ErrorIs(t, err, types.ErrUpdateObserver) }) t.Run("unable to update tombstoned validator with with non operator account", func(t *testing.T) { @@ -135,7 +135,7 @@ func TestMsgServer_UpdateObserver(t *testing.T) { k.GetStakingKeeper().SetValidator(ctx, validator) consAddress, err := validator.GetConsAddr() - assert.NoError(t, err) + require.NoError(t, err) k.GetSlashingKeeper().SetValidatorSigningInfo(ctx, consAddress, slashingtypes.ValidatorSigningInfo{ Address: consAddress.String(), StartHeight: 0, @@ -145,7 +145,7 @@ func TestMsgServer_UpdateObserver(t *testing.T) { }) accAddressOfValidator, err := types.GetAccAddressFromOperatorAddress(validator.OperatorAddress) - assert.NoError(t, err) + require.NoError(t, err) count := uint64(0) k.SetObserverSet(ctx, types.ObserverSet{ @@ -162,7 +162,7 @@ func TestMsgServer_UpdateObserver(t *testing.T) { }) newOperatorAddress, err := types.GetAccAddressFromOperatorAddress(validatorNew.OperatorAddress) - assert.NoError(t, err) + require.NoError(t, err) _, err = srv.UpdateObserver(sdk.WrapSDKContext(ctx), &types.MsgUpdateObserver{ Creator: sample.AccAddress(), @@ -170,7 +170,7 @@ func TestMsgServer_UpdateObserver(t *testing.T) { NewObserverAddress: newOperatorAddress.String(), UpdateReason: types.ObserverUpdateReason_Tombstoned, }) - assert.ErrorIs(t, err, types.ErrUpdateObserver) + require.ErrorIs(t, err, types.ErrUpdateObserver) }) t.Run("unable to update non-tombstoned observer with update reason tombstoned", func(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) @@ -186,7 +186,7 @@ func TestMsgServer_UpdateObserver(t *testing.T) { k.GetStakingKeeper().SetValidator(ctx, validator) consAddress, err := validator.GetConsAddr() - assert.NoError(t, err) + require.NoError(t, err) k.GetSlashingKeeper().SetValidatorSigningInfo(ctx, consAddress, slashingtypes.ValidatorSigningInfo{ Address: consAddress.String(), StartHeight: 0, @@ -196,7 +196,7 @@ func TestMsgServer_UpdateObserver(t *testing.T) { }) accAddressOfValidator, err := types.GetAccAddressFromOperatorAddress(validator.OperatorAddress) - assert.NoError(t, err) + require.NoError(t, err) count := uint64(0) k.SetObserverSet(ctx, types.ObserverSet{ ObserverList: []string{accAddressOfValidator.String()}, @@ -212,7 +212,7 @@ func TestMsgServer_UpdateObserver(t *testing.T) { }) newOperatorAddress, err := types.GetAccAddressFromOperatorAddress(validatorNew.OperatorAddress) - assert.NoError(t, err) + require.NoError(t, err) _, err = srv.UpdateObserver(sdk.WrapSDKContext(ctx), &types.MsgUpdateObserver{ Creator: accAddressOfValidator.String(), @@ -220,7 +220,7 @@ func TestMsgServer_UpdateObserver(t *testing.T) { NewObserverAddress: newOperatorAddress.String(), UpdateReason: types.ObserverUpdateReason_Tombstoned, }) - assert.ErrorIs(t, err, types.ErrUpdateObserver) + require.ErrorIs(t, err, types.ErrUpdateObserver) }) t.Run("unable to update observer with no node account", func(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) @@ -236,7 +236,7 @@ func TestMsgServer_UpdateObserver(t *testing.T) { k.GetStakingKeeper().SetValidator(ctx, validator) consAddress, err := validator.GetConsAddr() - assert.NoError(t, err) + require.NoError(t, err) k.GetSlashingKeeper().SetValidatorSigningInfo(ctx, consAddress, slashingtypes.ValidatorSigningInfo{ Address: consAddress.String(), StartHeight: 0, @@ -246,7 +246,7 @@ func TestMsgServer_UpdateObserver(t *testing.T) { }) accAddressOfValidator, err := types.GetAccAddressFromOperatorAddress(validator.OperatorAddress) - assert.NoError(t, err) + require.NoError(t, err) count := uint64(0) k.SetObserverSet(ctx, types.ObserverSet{ ObserverList: []string{accAddressOfValidator.String()}, @@ -258,7 +258,7 @@ func TestMsgServer_UpdateObserver(t *testing.T) { }) newOperatorAddress, err := types.GetAccAddressFromOperatorAddress(validatorNew.OperatorAddress) - assert.NoError(t, err) + require.NoError(t, err) _, err = srv.UpdateObserver(sdk.WrapSDKContext(ctx), &types.MsgUpdateObserver{ Creator: accAddressOfValidator.String(), @@ -266,7 +266,7 @@ func TestMsgServer_UpdateObserver(t *testing.T) { NewObserverAddress: newOperatorAddress.String(), UpdateReason: types.ObserverUpdateReason_Tombstoned, }) - assert.ErrorIs(t, err, types.ErrNodeAccountNotFound) + require.ErrorIs(t, err, types.ErrNodeAccountNotFound) }) t.Run("unable to update observer when last observer count is missing", func(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) @@ -282,7 +282,7 @@ func TestMsgServer_UpdateObserver(t *testing.T) { k.GetStakingKeeper().SetValidator(ctx, validator) consAddress, err := validator.GetConsAddr() - assert.NoError(t, err) + require.NoError(t, err) k.GetSlashingKeeper().SetValidatorSigningInfo(ctx, consAddress, slashingtypes.ValidatorSigningInfo{ Address: consAddress.String(), StartHeight: 0, @@ -292,7 +292,7 @@ func TestMsgServer_UpdateObserver(t *testing.T) { }) accAddressOfValidator, err := types.GetAccAddressFromOperatorAddress(validator.OperatorAddress) - assert.NoError(t, err) + require.NoError(t, err) count := uint64(0) k.SetObserverSet(ctx, types.ObserverSet{ ObserverList: []string{accAddressOfValidator.String()}, @@ -303,7 +303,7 @@ func TestMsgServer_UpdateObserver(t *testing.T) { }) newOperatorAddress, err := types.GetAccAddressFromOperatorAddress(validatorNew.OperatorAddress) - assert.NoError(t, err) + require.NoError(t, err) _, err = srv.UpdateObserver(sdk.WrapSDKContext(ctx), &types.MsgUpdateObserver{ Creator: accAddressOfValidator.String(), @@ -311,7 +311,7 @@ func TestMsgServer_UpdateObserver(t *testing.T) { NewObserverAddress: newOperatorAddress.String(), UpdateReason: types.ObserverUpdateReason_Tombstoned, }) - assert.ErrorIs(t, err, types.ErrLastObserverCountNotFound) + require.ErrorIs(t, err, types.ErrLastObserverCountNotFound) }) t.Run("update observer using admin policy", func(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) @@ -330,7 +330,7 @@ func TestMsgServer_UpdateObserver(t *testing.T) { k.GetStakingKeeper().SetValidator(ctx, validator) consAddress, err := validator.GetConsAddr() - assert.NoError(t, err) + require.NoError(t, err) k.GetSlashingKeeper().SetValidatorSigningInfo(ctx, consAddress, slashingtypes.ValidatorSigningInfo{ Address: consAddress.String(), StartHeight: 0, @@ -340,7 +340,7 @@ func TestMsgServer_UpdateObserver(t *testing.T) { }) accAddressOfValidator, err := types.GetAccAddressFromOperatorAddress(validator.OperatorAddress) - assert.NoError(t, err) + require.NoError(t, err) count := uint64(0) k.SetObserverSet(ctx, types.ObserverSet{ ObserverList: []string{accAddressOfValidator.String()}, @@ -351,7 +351,7 @@ func TestMsgServer_UpdateObserver(t *testing.T) { }) newOperatorAddress, err := types.GetAccAddressFromOperatorAddress(validatorNew.OperatorAddress) - assert.NoError(t, err) + require.NoError(t, err) k.SetLastObserverCount(ctx, &types.LastObserverCount{ Count: count, @@ -363,10 +363,10 @@ func TestMsgServer_UpdateObserver(t *testing.T) { NewObserverAddress: newOperatorAddress.String(), UpdateReason: types.ObserverUpdateReason_AdminUpdate, }) - assert.NoError(t, err) + require.NoError(t, err) acc, found := k.GetNodeAccount(ctx, newOperatorAddress.String()) - assert.True(t, found) - assert.Equal(t, newOperatorAddress.String(), acc.Operator) + require.True(t, found) + require.Equal(t, newOperatorAddress.String(), acc.Operator) }) t.Run("fail to update observer using regular account and update type admin", func(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) @@ -383,7 +383,7 @@ func TestMsgServer_UpdateObserver(t *testing.T) { k.GetStakingKeeper().SetValidator(ctx, validator) consAddress, err := validator.GetConsAddr() - assert.NoError(t, err) + require.NoError(t, err) k.GetSlashingKeeper().SetValidatorSigningInfo(ctx, consAddress, slashingtypes.ValidatorSigningInfo{ Address: consAddress.String(), StartHeight: 0, @@ -393,7 +393,7 @@ func TestMsgServer_UpdateObserver(t *testing.T) { }) accAddressOfValidator, err := types.GetAccAddressFromOperatorAddress(validator.OperatorAddress) - assert.NoError(t, err) + require.NoError(t, err) count := uint64(0) k.SetObserverSet(ctx, types.ObserverSet{ ObserverList: []string{accAddressOfValidator.String()}, @@ -405,7 +405,7 @@ func TestMsgServer_UpdateObserver(t *testing.T) { }) newOperatorAddress, err := types.GetAccAddressFromOperatorAddress(validatorNew.OperatorAddress) - assert.NoError(t, err) + require.NoError(t, err) k.SetLastObserverCount(ctx, &types.LastObserverCount{ Count: count, @@ -417,7 +417,7 @@ func TestMsgServer_UpdateObserver(t *testing.T) { NewObserverAddress: newOperatorAddress.String(), UpdateReason: types.ObserverUpdateReason_AdminUpdate, }) - assert.ErrorIs(t, err, types.ErrUpdateObserver) + require.ErrorIs(t, err, types.ErrUpdateObserver) }) } @@ -426,9 +426,9 @@ func TestUpdateObserverList(t *testing.T) { oldObserverAddress := sample.AccAddress() newObserverAddress := sample.AccAddress() list := []string{sample.AccAddress(), sample.AccAddress(), sample.AccAddress(), oldObserverAddress} - assert.Equal(t, oldObserverAddress, list[3]) + require.Equal(t, oldObserverAddress, list[3]) keeper.UpdateObserverList(list, oldObserverAddress, newObserverAddress) - assert.Equal(t, 4, len(list)) - assert.Equal(t, newObserverAddress, list[3]) + require.Equal(t, 4, len(list)) + require.Equal(t, newObserverAddress, list[3]) }) } diff --git a/x/observer/keeper/node_account_test.go b/x/observer/keeper/node_account_test.go index 034b48ba67..26a5c47d1c 100644 --- a/x/observer/keeper/node_account_test.go +++ b/x/observer/keeper/node_account_test.go @@ -5,7 +5,7 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/x/observer/types" ) @@ -25,8 +25,8 @@ func TestNodeAccountGet(t *testing.T) { items := createNNodeAccount(keeper, ctx, 10) for _, item := range items { rst, found := keeper.GetNodeAccount(ctx, item.Operator) - assert.True(t, found) - assert.Equal(t, item, rst) + require.True(t, found) + require.Equal(t, item, rst) } } func TestNodeAccountRemove(t *testing.T) { @@ -35,12 +35,12 @@ func TestNodeAccountRemove(t *testing.T) { for _, item := range items { keeper.RemoveNodeAccount(ctx, item.Operator) _, found := keeper.GetNodeAccount(ctx, item.Operator) - assert.False(t, found) + require.False(t, found) } } func TestNodeAccountGetAll(t *testing.T) { keeper, ctx := SetupKeeper(t) items := createNNodeAccount(keeper, ctx, 10) - assert.Equal(t, items, keeper.GetAllNodeAccount(ctx)) + require.Equal(t, items, keeper.GetAllNodeAccount(ctx)) } diff --git a/x/observer/keeper/nonce_to_cctx_test.go b/x/observer/keeper/nonce_to_cctx_test.go index 9fc65fcea2..1cbd023fbd 100644 --- a/x/observer/keeper/nonce_to_cctx_test.go +++ b/x/observer/keeper/nonce_to_cctx_test.go @@ -3,7 +3,7 @@ package keeper_test import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" ) @@ -17,8 +17,8 @@ func TestKeeper_GetNonceToCctx(t *testing.T) { } for _, n := range nonceToCctxList { rst, found := k.GetNonceToCctx(ctx, n.Tss, n.ChainId, n.Nonce) - assert.True(t, found) - assert.Equal(t, n, rst) + require.True(t, found) + require.Equal(t, n, rst) } }) t.Run("Get nonce to cctx not found", func(t *testing.T) { @@ -28,7 +28,7 @@ func TestKeeper_GetNonceToCctx(t *testing.T) { k.SetNonceToCctx(ctx, n) } _, found := k.GetNonceToCctx(ctx, "not_found", 1, 1) - assert.False(t, found) + require.False(t, found) }) t.Run("Get all nonce to cctx", func(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) @@ -37,6 +37,6 @@ func TestKeeper_GetNonceToCctx(t *testing.T) { k.SetNonceToCctx(ctx, n) } rst := k.GetAllNonceToCctx(ctx) - assert.Equal(t, nonceToCctxList, rst) + require.Equal(t, nonceToCctxList, rst) }) } diff --git a/x/observer/keeper/nonces_test.go b/x/observer/keeper/nonces_test.go index 2e201ae67e..aaf7369df1 100644 --- a/x/observer/keeper/nonces_test.go +++ b/x/observer/keeper/nonces_test.go @@ -3,7 +3,7 @@ package keeper_test import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" ) @@ -16,8 +16,8 @@ func TestChainNoncesGet(t *testing.T) { } for _, item := range items { rst, found := k.GetChainNonces(ctx, item.Index) - assert.True(t, found) - assert.Equal(t, item, rst) + require.True(t, found) + require.Equal(t, item, rst) } } func TestChainNoncesRemove(t *testing.T) { @@ -29,7 +29,7 @@ func TestChainNoncesRemove(t *testing.T) { for _, item := range items { k.RemoveChainNonces(ctx, item.Index) _, found := k.GetChainNonces(ctx, item.Index) - assert.False(t, found) + require.False(t, found) } } @@ -39,5 +39,5 @@ func TestChainNoncesGetAll(t *testing.T) { for _, item := range items { k.SetChainNonces(ctx, item) } - assert.Equal(t, items, k.GetAllChainNonces(ctx)) + require.Equal(t, items, k.GetAllChainNonces(ctx)) } diff --git a/x/observer/keeper/observer_set_test.go b/x/observer/keeper/observer_set_test.go index f1ca38fc8c..ca7212704a 100644 --- a/x/observer/keeper/observer_set_test.go +++ b/x/observer/keeper/observer_set_test.go @@ -3,7 +3,7 @@ package keeper_test import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" ) @@ -14,8 +14,8 @@ func TestKeeper_GetObserverSet(t *testing.T) { os := sample.ObserverSet(10) k.SetObserverSet(ctx, os) tfm, found := k.GetObserverSet(ctx) - assert.True(t, found) - assert.Equal(t, os, tfm) + require.True(t, found) + require.Equal(t, os, tfm) }) } @@ -24,8 +24,8 @@ func TestKeeper_IsAddressPartOfObserverSet(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) os := sample.ObserverSet(10) k.SetObserverSet(ctx, os) - assert.True(t, k.IsAddressPartOfObserverSet(ctx, os.ObserverList[0])) - assert.False(t, k.IsAddressPartOfObserverSet(ctx, sample.AccAddress())) + require.True(t, k.IsAddressPartOfObserverSet(ctx, os.ObserverList[0])) + require.False(t, k.IsAddressPartOfObserverSet(ctx, sample.AccAddress())) }) } @@ -36,11 +36,11 @@ func TestKeeper_AddObserverToSet(t *testing.T) { k.SetObserverSet(ctx, os) newObserver := sample.AccAddress() k.AddObserverToSet(ctx, newObserver) - assert.True(t, k.IsAddressPartOfObserverSet(ctx, newObserver)) - assert.False(t, k.IsAddressPartOfObserverSet(ctx, sample.AccAddress())) + require.True(t, k.IsAddressPartOfObserverSet(ctx, newObserver)) + require.False(t, k.IsAddressPartOfObserverSet(ctx, sample.AccAddress())) osNew, found := k.GetObserverSet(ctx) - assert.True(t, found) - assert.Len(t, osNew.ObserverList, len(os.ObserverList)+1) + require.True(t, found) + require.Len(t, osNew.ObserverList, len(os.ObserverList)+1) }) } @@ -50,10 +50,10 @@ func TestKeeper_RemoveObserverFromSet(t *testing.T) { os := sample.ObserverSet(10) k.SetObserverSet(ctx, os) k.RemoveObserverFromSet(ctx, os.ObserverList[0]) - assert.False(t, k.IsAddressPartOfObserverSet(ctx, os.ObserverList[0])) + require.False(t, k.IsAddressPartOfObserverSet(ctx, os.ObserverList[0])) osNew, found := k.GetObserverSet(ctx) - assert.True(t, found) - assert.Len(t, osNew.ObserverList, len(os.ObserverList)-1) + require.True(t, found) + require.Len(t, osNew.ObserverList, len(os.ObserverList)-1) }) } @@ -66,10 +66,10 @@ func TestKeeper_UpdateObserverAddress(t *testing.T) { observerSet.ObserverList = append(observerSet.ObserverList, oldObserverAddress) k.SetObserverSet(ctx, observerSet) err := k.UpdateObserverAddress(ctx, oldObserverAddress, newObserverAddress) - assert.NoError(t, err) + require.NoError(t, err) observerSet, found := k.GetObserverSet(ctx) - assert.True(t, found) - assert.Equal(t, newObserverAddress, observerSet.ObserverList[len(observerSet.ObserverList)-1]) + require.True(t, found) + require.Equal(t, newObserverAddress, observerSet.ObserverList[len(observerSet.ObserverList)-1]) }) t.Run("update observer address long observerList", func(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) @@ -79,10 +79,10 @@ func TestKeeper_UpdateObserverAddress(t *testing.T) { observerSet.ObserverList = append(observerSet.ObserverList, oldObserverAddress) k.SetObserverSet(ctx, observerSet) err := k.UpdateObserverAddress(ctx, oldObserverAddress, newObserverAddress) - assert.NoError(t, err) + require.NoError(t, err) observerMappers, found := k.GetObserverSet(ctx) - assert.True(t, found) - assert.Equal(t, newObserverAddress, observerMappers.ObserverList[len(observerMappers.ObserverList)-1]) + require.True(t, found) + require.Equal(t, newObserverAddress, observerMappers.ObserverList[len(observerMappers.ObserverList)-1]) }) t.Run("update observer address short observerList", func(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) @@ -92,9 +92,9 @@ func TestKeeper_UpdateObserverAddress(t *testing.T) { observerSet.ObserverList = append(observerSet.ObserverList, oldObserverAddress) k.SetObserverSet(ctx, observerSet) err := k.UpdateObserverAddress(ctx, oldObserverAddress, newObserverAddress) - assert.NoError(t, err) + require.NoError(t, err) observerMappers, found := k.GetObserverSet(ctx) - assert.True(t, found) - assert.Equal(t, newObserverAddress, observerMappers.ObserverList[len(observerMappers.ObserverList)-1]) + require.True(t, found) + require.Equal(t, newObserverAddress, observerMappers.ObserverList[len(observerMappers.ObserverList)-1]) }) } diff --git a/x/observer/keeper/params_test.go b/x/observer/keeper/params_test.go index 744e8e6080..5ec4c260a3 100644 --- a/x/observer/keeper/params_test.go +++ b/x/observer/keeper/params_test.go @@ -8,7 +8,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/tendermint/tendermint/crypto" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/x/observer/types" ) @@ -18,7 +18,7 @@ func TestGetParams(t *testing.T) { k.SetParams(ctx, params) - assert.EqualValues(t, params, k.GetParams(ctx)) + require.EqualValues(t, params, k.GetParams(ctx)) } func TestGenerateAddress(t *testing.T) { diff --git a/x/observer/keeper/pending_nonces_test.go b/x/observer/keeper/pending_nonces_test.go index 5fa115fd30..0cb61f090d 100644 --- a/x/observer/keeper/pending_nonces_test.go +++ b/x/observer/keeper/pending_nonces_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/cosmos/cosmos-sdk/types/query" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" ) @@ -21,12 +21,12 @@ func TestKeeper_PendingNoncesAll(t *testing.T) { k.SetPendingNonces(ctx, nonce) } rst, pageRes, err := k.GetAllPendingNoncesPaginated(ctx, &query.PageRequest{Limit: 10, CountTotal: true}) - assert.NoError(t, err) + require.NoError(t, err) sort.SliceStable(rst, func(i, j int) bool { return rst[i].ChainId < rst[j].ChainId }) - assert.Equal(t, nonces, rst) - assert.Equal(t, len(nonces), int(pageRes.Total)) + require.Equal(t, nonces, rst) + require.Equal(t, len(nonces), int(pageRes.Total)) }) t.Run("Get all pending nonces paginated by offset", func(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) @@ -39,13 +39,13 @@ func TestKeeper_PendingNoncesAll(t *testing.T) { } offset := 10 rst, pageRes, err := k.GetAllPendingNoncesPaginated(ctx, &query.PageRequest{Offset: uint64(offset), CountTotal: true}) - assert.NoError(t, err) + require.NoError(t, err) sort.SliceStable(rst, func(i, j int) bool { return rst[i].ChainId < rst[j].ChainId }) - assert.Subset(t, nonces, rst) - assert.Len(t, rst, len(nonces)-offset) - assert.Equal(t, len(nonces), int(pageRes.Total)) + require.Subset(t, nonces, rst) + require.Len(t, rst, len(nonces)-offset) + require.Equal(t, len(nonces), int(pageRes.Total)) }) t.Run("Get all pending nonces ", func(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) @@ -57,10 +57,10 @@ func TestKeeper_PendingNoncesAll(t *testing.T) { k.SetPendingNonces(ctx, nonce) } rst, err := k.GetAllPendingNonces(ctx) - assert.NoError(t, err) + require.NoError(t, err) sort.SliceStable(rst, func(i, j int) bool { return rst[i].ChainId < rst[j].ChainId }) - assert.Equal(t, nonces, rst) + require.Equal(t, nonces, rst) }) } diff --git a/x/observer/keeper/tss_funds_migrator_test.go b/x/observer/keeper/tss_funds_migrator_test.go index b7cd45bec1..62d622e179 100644 --- a/x/observer/keeper/tss_funds_migrator_test.go +++ b/x/observer/keeper/tss_funds_migrator_test.go @@ -3,7 +3,7 @@ package keeper_test import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" ) @@ -14,8 +14,8 @@ func TestKeeper_GetTssFundMigrator(t *testing.T) { chain := sample.TssFundsMigrator(1) k.SetFundMigrator(ctx, chain) tfm, found := k.GetFundMigrator(ctx, chain.ChainId) - assert.True(t, found) - assert.Equal(t, chain, tfm) + require.True(t, found) + require.Equal(t, chain, tfm) }) t.Run("Verify only one migrator can be created for a chain", func(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) @@ -25,8 +25,8 @@ func TestKeeper_GetTssFundMigrator(t *testing.T) { tfm2.MigrationCctxIndex = "sampleIndex2" k.SetFundMigrator(ctx, tfm2) migratorList := k.GetAllTssFundMigrators(ctx) - assert.Equal(t, 1, len(migratorList)) - assert.Equal(t, tfm2, migratorList[0]) + require.Equal(t, 1, len(migratorList)) + require.Equal(t, tfm2, migratorList[0]) }) } diff --git a/x/observer/keeper/tss_test.go b/x/observer/keeper/tss_test.go index 91994ed6f0..0af8bae7f3 100644 --- a/x/observer/keeper/tss_test.go +++ b/x/observer/keeper/tss_test.go @@ -6,7 +6,7 @@ import ( "testing" "github.com/cosmos/cosmos-sdk/types/query" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" "google.golang.org/grpc/codes" @@ -21,8 +21,8 @@ func TestTSSGet(t *testing.T) { tss := sample.Tss() k.SetTSS(ctx, tss) tssQueried, found := k.GetTSS(ctx) - assert.True(t, found) - assert.Equal(t, tss, tssQueried) + require.True(t, found) + require.Equal(t, tss, tssQueried) } func TestTSSRemove(t *testing.T) { @@ -31,7 +31,7 @@ func TestTSSRemove(t *testing.T) { k.SetTSS(ctx, tss) k.RemoveTSS(ctx) _, found := k.GetTSS(ctx) - assert.False(t, found) + require.False(t, found) } func TestTSSQuerySingle(t *testing.T) { @@ -60,9 +60,9 @@ func TestTSSQuerySingle(t *testing.T) { t.Run(tc.desc, func(t *testing.T) { response, err := k.TSS(wctx, tc.request) if tc.err != nil { - assert.ErrorIs(t, err, tc.err) + require.ErrorIs(t, err, tc.err) } else { - assert.Equal(t, tc.response, response) + require.Equal(t, tc.response, response) } }) } @@ -100,13 +100,13 @@ func TestTSSQueryHistory(t *testing.T) { request := &types.QueryTssHistoryRequest{} response, err := keeper.TssHistory(wctx, request) if tc.err != nil { - assert.ErrorIs(t, err, tc.err) + require.ErrorIs(t, err, tc.err) } else { - assert.Equal(t, len(tssList), len(response.TssList)) + require.Equal(t, len(tssList), len(response.TssList)) prevTss, found := keeper.GetPreviousTSS(ctx) - assert.Equal(t, tc.foundPrevious, found) + require.Equal(t, tc.foundPrevious, found) if found { - assert.Equal(t, tssList[len(tssList)-2], prevTss) + require.Equal(t, tssList[len(tssList)-2], prevTss) } } }) @@ -121,15 +121,15 @@ func TestKeeper_TssHistory(t *testing.T) { k.SetTSSHistory(ctx, tss) } rst, pageRes, err := k.GetAllTSSPaginated(ctx, &query.PageRequest{Limit: 20, CountTotal: true}) - assert.NoError(t, err) + require.NoError(t, err) sort.Slice(tssList, func(i, j int) bool { return tssList[i].FinalizedZetaHeight < tssList[j].FinalizedZetaHeight }) sort.Slice(rst, func(i, j int) bool { return rst[i].FinalizedZetaHeight < rst[j].FinalizedZetaHeight }) - assert.Equal(t, tssList, rst) - assert.Equal(t, len(tssList), int(pageRes.Total)) + require.Equal(t, tssList, rst) + require.Equal(t, len(tssList), int(pageRes.Total)) }) t.Run("Get tss history paginated by offset", func(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) @@ -139,16 +139,16 @@ func TestKeeper_TssHistory(t *testing.T) { k.SetTSSHistory(ctx, tss) } rst, pageRes, err := k.GetAllTSSPaginated(ctx, &query.PageRequest{Offset: uint64(offset), CountTotal: true}) - assert.NoError(t, err) + require.NoError(t, err) sort.Slice(tssList, func(i, j int) bool { return tssList[i].FinalizedZetaHeight < tssList[j].FinalizedZetaHeight }) sort.Slice(rst, func(i, j int) bool { return rst[i].FinalizedZetaHeight < rst[j].FinalizedZetaHeight }) - assert.Subset(t, tssList, rst) - assert.Equal(t, len(tssList)-offset, len(rst)) - assert.Equal(t, len(tssList), int(pageRes.Total)) + require.Subset(t, tssList, rst) + require.Equal(t, len(tssList)-offset, len(rst)) + require.Equal(t, len(tssList), int(pageRes.Total)) }) t.Run("Get all TSS without pagination", func(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) @@ -163,7 +163,7 @@ func TestKeeper_TssHistory(t *testing.T) { sort.Slice(rst, func(i, j int) bool { return rst[i].FinalizedZetaHeight < rst[j].FinalizedZetaHeight }) - assert.Equal(t, tssList, rst) + require.Equal(t, tssList, rst) }) t.Run("Get historical TSS", func(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) @@ -173,7 +173,7 @@ func TestKeeper_TssHistory(t *testing.T) { } r := rand.Intn((len(tssList)-1)-0) + 0 tss, found := k.GetHistoricalTssByFinalizedHeight(ctx, tssList[r].FinalizedZetaHeight) - assert.True(t, found) - assert.Equal(t, tssList[r], tss) + require.True(t, found) + require.Equal(t, tssList[r], tss) }) } diff --git a/x/observer/keeper/utils_test.go b/x/observer/keeper/utils_test.go index 3e99956e71..6534fc6200 100644 --- a/x/observer/keeper/utils_test.go +++ b/x/observer/keeper/utils_test.go @@ -7,7 +7,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" zetacommon "github.com/zeta-chain/zetacore/common" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -36,7 +36,7 @@ func getValidEthChainIDWithIndex(t *testing.T, index int) int64 { case 1: return zetacommon.GoerliChain().ChainId default: - assert.Fail(t, "invalid index") + require.Fail(t, "invalid index") } return 0 } @@ -51,7 +51,7 @@ func TestKeeper_IsAuthorized(t *testing.T) { validator := sample.Validator(t, r) k.GetStakingKeeper().SetValidator(ctx, validator) consAddress, err := validator.GetConsAddr() - assert.NoError(t, err) + require.NoError(t, err) k.GetSlashingKeeper().SetValidatorSigningInfo(ctx, consAddress, slashingtypes.ValidatorSigningInfo{ Address: consAddress.String(), StartHeight: 0, @@ -65,7 +65,7 @@ func TestKeeper_IsAuthorized(t *testing.T) { k.SetObserverSet(ctx, types.ObserverSet{ ObserverList: []string{accAddressOfValidator.String()}, }) - assert.True(t, k.IsAuthorized(ctx, accAddressOfValidator.String())) + require.True(t, k.IsAuthorized(ctx, accAddressOfValidator.String())) }) t.Run("not authorized for tombstoned observer", func(t *testing.T) { @@ -77,7 +77,7 @@ func TestKeeper_IsAuthorized(t *testing.T) { validator := sample.Validator(t, r) k.GetStakingKeeper().SetValidator(ctx, validator) consAddress, err := validator.GetConsAddr() - assert.NoError(t, err) + require.NoError(t, err) k.GetSlashingKeeper().SetValidatorSigningInfo(ctx, consAddress, slashingtypes.ValidatorSigningInfo{ Address: consAddress.String(), StartHeight: 0, @@ -91,7 +91,7 @@ func TestKeeper_IsAuthorized(t *testing.T) { ObserverList: []string{accAddressOfValidator.String()}, }) - assert.False(t, k.IsAuthorized(ctx, accAddressOfValidator.String())) + require.False(t, k.IsAuthorized(ctx, accAddressOfValidator.String())) }) t.Run("not authorized for non-validator observer", func(t *testing.T) { @@ -103,7 +103,7 @@ func TestKeeper_IsAuthorized(t *testing.T) { validator := sample.Validator(t, r) consAddress, err := validator.GetConsAddr() - assert.NoError(t, err) + require.NoError(t, err) k.GetSlashingKeeper().SetValidatorSigningInfo(ctx, consAddress, slashingtypes.ValidatorSigningInfo{ Address: consAddress.String(), StartHeight: 0, @@ -117,7 +117,7 @@ func TestKeeper_IsAuthorized(t *testing.T) { ObserverList: []string{accAddressOfValidator.String()}, }) - assert.False(t, k.IsAuthorized(ctx, accAddressOfValidator.String())) + require.False(t, k.IsAuthorized(ctx, accAddressOfValidator.String())) }) } diff --git a/x/observer/migrations/v3/migrate_test.go b/x/observer/migrations/v3/migrate_test.go index a2b3574bff..604fd0a9c7 100644 --- a/x/observer/migrations/v3/migrate_test.go +++ b/x/observer/migrations/v3/migrate_test.go @@ -3,7 +3,7 @@ package v3_test import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" v3 "github.com/zeta-chain/zetacore/x/observer/migrations/v3" @@ -18,9 +18,9 @@ func TestMigrateStore(t *testing.T) { params.AdminPolicy = []*types.Admin_Policy{} k.SetParams(ctx, params) err := v3.MigrateStore(ctx, k) - assert.NoError(t, err) + require.NoError(t, err) params = k.GetParams(ctx) - assert.Len(t, params.AdminPolicy, 0) + require.Len(t, params.AdminPolicy, 0) // update admin policy admin := sample.AccAddress() @@ -41,11 +41,11 @@ func TestMigrateStore(t *testing.T) { } k.SetParams(ctx, params) err = v3.MigrateStore(ctx, k) - assert.NoError(t, err) + require.NoError(t, err) params = k.GetParams(ctx) - assert.Len(t, params.AdminPolicy, 2) - assert.Equal(t, params.AdminPolicy[0].PolicyType, types.Policy_Type_group1) - assert.Equal(t, params.AdminPolicy[1].PolicyType, types.Policy_Type_group2) - assert.Equal(t, params.AdminPolicy[0].Address, admin) - assert.Equal(t, params.AdminPolicy[1].Address, admin) + require.Len(t, params.AdminPolicy, 2) + require.Equal(t, params.AdminPolicy[0].PolicyType, types.Policy_Type_group1) + require.Equal(t, params.AdminPolicy[1].PolicyType, types.Policy_Type_group2) + require.Equal(t, params.AdminPolicy[0].Address, admin) + require.Equal(t, params.AdminPolicy[1].Address, admin) } diff --git a/x/observer/migrations/v4/migrate_test.go b/x/observer/migrations/v4/migrate_test.go index b7d025fa60..a5bfd67f56 100644 --- a/x/observer/migrations/v4/migrate_test.go +++ b/x/observer/migrations/v4/migrate_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/cosmos/cosmos-sdk/store/prefix" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" v4 "github.com/zeta-chain/zetacore/x/observer/migrations/v4" "github.com/zeta-chain/zetacore/x/observer/types" @@ -22,10 +22,10 @@ func TestMigrateCrosschainFlags(t *testing.T) { store.Set([]byte{0}, val) err := v4.MigrateCrosschainFlags(ctx, k.StoreKey(), k.Codec()) - assert.NoError(t, err) + require.NoError(t, err) flags, found := k.GetCrosschainFlags(ctx) - assert.True(t, found) - assert.True(t, flags.BlockHeaderVerificationFlags.IsBtcTypeChainEnabled) - assert.True(t, flags.BlockHeaderVerificationFlags.IsEthTypeChainEnabled) + require.True(t, found) + require.True(t, flags.BlockHeaderVerificationFlags.IsBtcTypeChainEnabled) + require.True(t, flags.BlockHeaderVerificationFlags.IsEthTypeChainEnabled) } diff --git a/x/observer/migrations/v5/migrate_test.go b/x/observer/migrations/v5/migrate_test.go index 0ceebf9e03..8b83d5d0ed 100644 --- a/x/observer/migrations/v5/migrate_test.go +++ b/x/observer/migrations/v5/migrate_test.go @@ -5,7 +5,7 @@ import ( "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" "github.com/zeta-chain/zetacore/testutil/sample" @@ -22,11 +22,11 @@ func TestMigrateObserverMapper(t *testing.T) { legacyObserverMapperStore.Set(types.KeyPrefix(legacyObserverMapper.Index), k.Codec().MustMarshal(legacyObserverMapper)) } err := v5.MigrateObserverMapper(ctx, k.StoreKey(), k.Codec()) - assert.NoError(t, err) + require.NoError(t, err) observerSet, found := k.GetObserverSet(ctx) - assert.True(t, found) + require.True(t, found) - assert.Equal(t, legacyObserverMapperList[0].ObserverList, observerSet.ObserverList) + require.Equal(t, legacyObserverMapperList[0].ObserverList, observerSet.ObserverList) iterator := sdk.KVStorePrefixIterator(legacyObserverMapperStore, []byte{}) defer iterator.Close() @@ -38,7 +38,7 @@ func TestMigrateObserverMapper(t *testing.T) { observerMappers = append(observerMappers, &val) } } - assert.Equal(t, 0, len(observerMappers)) + require.Equal(t, 0, len(observerMappers)) }) } @@ -58,13 +58,13 @@ func TestMigrateObserverParams(t *testing.T) { // set observer params dec42, err := sdk.NewDecFromStr("0.42") - assert.NoError(t, err) + require.NoError(t, err) dec43, err := sdk.NewDecFromStr("0.43") - assert.NoError(t, err) + require.NoError(t, err) dec1000, err := sdk.NewDecFromStr("1000.0") - assert.NoError(t, err) + require.NoError(t, err) dec1001, err := sdk.NewDecFromStr("1001.0") - assert.NoError(t, err) + require.NoError(t, err) params := types.Params{ ObserverParams: []*types.ObserverParams{ { @@ -85,23 +85,23 @@ func TestMigrateObserverParams(t *testing.T) { // perform migration err = v5.MigrateObserverParams(ctx, *k) - assert.NoError(t, err) + require.NoError(t, err) // check chain params newChainParamsList, found := k.GetChainParamsList(ctx) - assert.True(t, found) + require.True(t, found) // unchanged values - assert.EqualValues(t, previousChainParamsList.ChainParams[0], newChainParamsList.ChainParams[0]) - assert.EqualValues(t, previousChainParamsList.ChainParams[3], newChainParamsList.ChainParams[3]) + require.EqualValues(t, previousChainParamsList.ChainParams[0], newChainParamsList.ChainParams[0]) + require.EqualValues(t, previousChainParamsList.ChainParams[3], newChainParamsList.ChainParams[3]) // changed values - assert.EqualValues(t, dec42, newChainParamsList.ChainParams[1].BallotThreshold) - assert.EqualValues(t, dec1000, newChainParamsList.ChainParams[1].MinObserverDelegation) - assert.EqualValues(t, dec43, newChainParamsList.ChainParams[2].BallotThreshold) - assert.EqualValues(t, dec1001, newChainParamsList.ChainParams[2].MinObserverDelegation) - assert.True(t, newChainParamsList.ChainParams[1].IsSupported) - assert.True(t, newChainParamsList.ChainParams[2].IsSupported) + require.EqualValues(t, dec42, newChainParamsList.ChainParams[1].BallotThreshold) + require.EqualValues(t, dec1000, newChainParamsList.ChainParams[1].MinObserverDelegation) + require.EqualValues(t, dec43, newChainParamsList.ChainParams[2].BallotThreshold) + require.EqualValues(t, dec1001, newChainParamsList.ChainParams[2].MinObserverDelegation) + require.True(t, newChainParamsList.ChainParams[1].IsSupported) + require.True(t, newChainParamsList.ChainParams[2].IsSupported) // check remaining values are unchanged previousChainParamsList.ChainParams[1].BallotThreshold = dec42 @@ -110,6 +110,6 @@ func TestMigrateObserverParams(t *testing.T) { previousChainParamsList.ChainParams[2].MinObserverDelegation = dec1001 previousChainParamsList.ChainParams[1].IsSupported = true previousChainParamsList.ChainParams[2].IsSupported = true - assert.EqualValues(t, previousChainParamsList.ChainParams[1], newChainParamsList.ChainParams[1]) - assert.EqualValues(t, previousChainParamsList.ChainParams[2], newChainParamsList.ChainParams[2]) + require.EqualValues(t, previousChainParamsList.ChainParams[1], newChainParamsList.ChainParams[1]) + require.EqualValues(t, previousChainParamsList.ChainParams[2], newChainParamsList.ChainParams[2]) } diff --git a/x/observer/migrations/v6/migrate_test.go b/x/observer/migrations/v6/migrate_test.go index 574ece4be4..925c1b0b32 100644 --- a/x/observer/migrations/v6/migrate_test.go +++ b/x/observer/migrations/v6/migrate_test.go @@ -4,7 +4,7 @@ import ( "math" "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" keepertest "github.com/zeta-chain/zetacore/testutil/keeper" v6 "github.com/zeta-chain/zetacore/x/observer/migrations/v6" "github.com/zeta-chain/zetacore/x/observer/types" @@ -49,12 +49,12 @@ func TestMigrateObserverParams(t *testing.T) { FinalizedZetaHeight: finalizedZetaHeight, }) err := v6.MigrateStore(ctx, k) - assert.NoError(t, err) + require.NoError(t, err) keygen, found := k.GetKeygen(ctx) - assert.True(t, found) - assert.Equal(t, types.KeygenStatus_KeyGenSuccess, keygen.Status) - assert.Equal(t, keygenHeight, keygenHeight) - assert.Equal(t, participantList, participantList) + require.True(t, found) + require.Equal(t, types.KeygenStatus_KeyGenSuccess, keygen.Status) + require.Equal(t, keygenHeight, keygenHeight) + require.Equal(t, participantList, participantList) }) t.Run("Migrate when keygen is not Pending", func(t *testing.T) { k, ctx := keepertest.ObserverKeeper(t) @@ -76,12 +76,12 @@ func TestMigrateObserverParams(t *testing.T) { GranteePubkeys: participantList, }) err := v6.MigrateStore(ctx, k) - assert.NoError(t, err) + require.NoError(t, err) keygen, found := k.GetKeygen(ctx) - assert.True(t, found) - assert.Equal(t, types.KeygenStatus_KeyGenSuccess, keygen.Status) - assert.Equal(t, keygen.BlockNumber, keygenHeight) - assert.Equal(t, keygen.GranteePubkeys, participantList) + require.True(t, found) + require.Equal(t, types.KeygenStatus_KeyGenSuccess, keygen.Status) + require.Equal(t, keygen.BlockNumber, keygenHeight) + require.Equal(t, keygen.GranteePubkeys, participantList) }) } diff --git a/x/observer/types/ballot_test.go b/x/observer/types/ballot_test.go index 0e087309e3..2bd6441c48 100644 --- a/x/observer/types/ballot_test.go +++ b/x/observer/types/ballot_test.go @@ -4,7 +4,7 @@ import ( "testing" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestBallot_AddVote(t *testing.T) { @@ -206,9 +206,9 @@ func TestBallot_AddVote(t *testing.T) { } finalBallot, isFinalized := ballot.IsFinalizingVote() - assert.Equal(t, test.finalStatus, finalBallot.BallotStatus) - assert.Equal(t, test.finalVotes, finalBallot.Votes) - assert.Equal(t, test.isFinalized, isFinalized) + require.Equal(t, test.finalStatus, finalBallot.BallotStatus) + require.Equal(t, test.finalVotes, finalBallot.Votes) + require.Equal(t, test.isFinalized, isFinalized) }) } } @@ -336,10 +336,10 @@ func TestBallot_IsFinalizingVote(t *testing.T) { ballot.Votes = append(ballot.Votes, vote) ballot, isFinalizingVote = ballot.IsFinalizingVote() if isFinalizingVote { - assert.Equal(t, test.finalizingVote, index) + require.Equal(t, test.finalizingVote, index) } } - assert.Equal(t, test.finalStatus, ballot.BallotStatus) + require.Equal(t, test.finalStatus, ballot.BallotStatus) }) } } @@ -391,7 +391,7 @@ func Test_BuildRewardsDistribution(t *testing.T) { } rewardsMap := map[string]int64{} ballot.BuildRewardsDistribution(rewardsMap) - assert.Equal(t, test.expectedMap, rewardsMap) + require.Equal(t, test.expectedMap, rewardsMap) }) } diff --git a/x/observer/types/chain_params_test.go b/x/observer/types/chain_params_test.go index 3d4d7ce456..0bdc9d814d 100644 --- a/x/observer/types/chain_params_test.go +++ b/x/observer/types/chain_params_test.go @@ -3,7 +3,7 @@ package types_test import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" "github.com/zeta-chain/zetacore/x/observer/types" . "gopkg.in/check.v1" @@ -13,22 +13,22 @@ func TestChainParamsList_Validate(t *testing.T) { t.Run("should return no error for default list", func(t *testing.T) { list := types.GetDefaultChainParams() err := list.Validate() - assert.NoError(t, err) + require.NoError(t, err) }) t.Run("should return error for invalid chain id", func(t *testing.T) { list := types.GetDefaultChainParams() list.ChainParams[0].ChainId = 999 err := list.Validate() - assert.Error(t, err) + require.Error(t, err) }) t.Run("should return error for duplicated chain ID", func(t *testing.T) { list := types.GetDefaultChainParams() list.ChainParams = append(list.ChainParams, list.ChainParams[0]) err := list.Validate() - assert.Error(t, err) - assert.Contains(t, err.Error(), "duplicated chain id") + require.Error(t, err) + require.Contains(t, err.Error(), "duplicated chain id") }) } @@ -46,8 +46,8 @@ func TestUpdateChainParamsSuiteSuite(t *testing.T) { func TestChainParamsEqual(t *testing.T) { params := types.GetDefaultChainParams() - assert.True(t, types.ChainParamsEqual(*params.ChainParams[0], *params.ChainParams[0])) - assert.False(t, types.ChainParamsEqual(*params.ChainParams[0], *params.ChainParams[1])) + require.True(t, types.ChainParamsEqual(*params.ChainParams[0], *params.ChainParams[0])) + require.False(t, types.ChainParamsEqual(*params.ChainParams[0], *params.ChainParams[1])) } func (s *UpdateChainParamsSuite) SetupTest() { @@ -87,9 +87,9 @@ func (s *UpdateChainParamsSuite) SetupTest() { func (s *UpdateChainParamsSuite) TestValidParams() { err := types.ValidateChainParams(s.evmParams) - assert.Nil(s.T(), err) + require.Nil(s.T(), err) err = types.ValidateChainParams(s.btcParams) - assert.Nil(s.T(), err) + require.Nil(s.T(), err) } func (s *UpdateChainParamsSuite) TestCommonParams() { @@ -101,99 +101,99 @@ func (s *UpdateChainParamsSuite) TestBTCParams() { copy := *s.btcParams copy.WatchUtxoTicker = 0 err := types.ValidateChainParams(©) - assert.NotNil(s.T(), err) + require.NotNil(s.T(), err) } func (s *UpdateChainParamsSuite) TestCoreContractAddresses() { copy := *s.evmParams copy.ZetaTokenContractAddress = "0x123" err := types.ValidateChainParams(©) - assert.NotNil(s.T(), err) + require.NotNil(s.T(), err) copy = *s.evmParams copy.ZetaTokenContractAddress = "733aB8b06DDDEf27Eaa72294B0d7c9cEF7f12db9" err = types.ValidateChainParams(©) - assert.NotNil(s.T(), err) + require.NotNil(s.T(), err) copy = *s.evmParams copy.ConnectorContractAddress = "0x123" err = types.ValidateChainParams(©) - assert.NotNil(s.T(), err) + require.NotNil(s.T(), err) copy = *s.evmParams copy.ConnectorContractAddress = "733aB8b06DDDEf27Eaa72294B0d7c9cEF7f12db9" err = types.ValidateChainParams(©) - assert.NotNil(s.T(), err) + require.NotNil(s.T(), err) copy = *s.evmParams copy.Erc20CustodyContractAddress = "0x123" err = types.ValidateChainParams(©) - assert.NotNil(s.T(), err) + require.NotNil(s.T(), err) copy = *s.evmParams copy.Erc20CustodyContractAddress = "733aB8b06DDDEf27Eaa72294B0d7c9cEF7f12db9" err = types.ValidateChainParams(©) - assert.NotNil(s.T(), err) + require.NotNil(s.T(), err) } func (s *UpdateChainParamsSuite) Validate(params *types.ChainParams) { copy := *params copy.ConfirmationCount = 0 err := types.ValidateChainParams(©) - assert.NotNil(s.T(), err) + require.NotNil(s.T(), err) copy = *params copy.GasPriceTicker = 0 err = types.ValidateChainParams(©) - assert.NotNil(s.T(), err) + require.NotNil(s.T(), err) copy.GasPriceTicker = 300 err = types.ValidateChainParams(©) - assert.Nil(s.T(), err) + require.Nil(s.T(), err) copy.GasPriceTicker = 301 err = types.ValidateChainParams(©) - assert.NotNil(s.T(), err) + require.NotNil(s.T(), err) copy = *params copy.InTxTicker = 0 err = types.ValidateChainParams(©) - assert.NotNil(s.T(), err) + require.NotNil(s.T(), err) copy.InTxTicker = 300 err = types.ValidateChainParams(©) - assert.Nil(s.T(), err) + require.Nil(s.T(), err) copy.InTxTicker = 301 err = types.ValidateChainParams(©) - assert.NotNil(s.T(), err) + require.NotNil(s.T(), err) copy = *params copy.OutTxTicker = 0 err = types.ValidateChainParams(©) - assert.NotNil(s.T(), err) + require.NotNil(s.T(), err) copy.OutTxTicker = 300 err = types.ValidateChainParams(©) - assert.Nil(s.T(), err) + require.Nil(s.T(), err) copy.OutTxTicker = 301 err = types.ValidateChainParams(©) - assert.NotNil(s.T(), err) + require.NotNil(s.T(), err) copy = *params copy.OutboundTxScheduleInterval = 0 err = types.ValidateChainParams(©) - assert.NotNil(s.T(), err) + require.NotNil(s.T(), err) copy.OutboundTxScheduleInterval = 100 err = types.ValidateChainParams(©) - assert.Nil(s.T(), err) + require.Nil(s.T(), err) copy.OutboundTxScheduleInterval = 101 err = types.ValidateChainParams(©) - assert.NotNil(s.T(), err) + require.NotNil(s.T(), err) copy = *params copy.OutboundTxScheduleLookahead = 0 err = types.ValidateChainParams(©) - assert.NotNil(s.T(), err) + require.NotNil(s.T(), err) copy.OutboundTxScheduleLookahead = 500 err = types.ValidateChainParams(©) - assert.Nil(s.T(), err) + require.Nil(s.T(), err) copy.OutboundTxScheduleLookahead = 501 err = types.ValidateChainParams(©) - assert.NotNil(s.T(), err) + require.NotNil(s.T(), err) } diff --git a/x/observer/types/genesis_test.go b/x/observer/types/genesis_test.go index d8ccb8414e..1ba8212a35 100644 --- a/x/observer/types/genesis_test.go +++ b/x/observer/types/genesis_test.go @@ -3,7 +3,7 @@ package types_test import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/x/observer/types" ) @@ -36,9 +36,9 @@ func TestGenesisState_Validate(t *testing.T) { t.Run(tc.desc, func(t *testing.T) { err := tc.genState.Validate() if tc.valid { - assert.NoError(t, err) + require.NoError(t, err) } else { - assert.Error(t, err) + require.Error(t, err) } }) } diff --git a/x/observer/types/message_add_observer_test.go b/x/observer/types/message_add_observer_test.go index bdc723f759..b60ade5dc3 100644 --- a/x/observer/types/message_add_observer_test.go +++ b/x/observer/types/message_add_observer_test.go @@ -4,7 +4,7 @@ import ( "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/observer/types" ) @@ -62,10 +62,10 @@ func TestMsgAddObserver_ValidateBasic(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - assert.ErrorIs(t, err, tt.err) + require.ErrorIs(t, err, tt.err) return } - assert.NoError(t, err) + require.NoError(t, err) }) } } diff --git a/x/observer/types/message_crosschain_flags_test.go b/x/observer/types/message_crosschain_flags_test.go index ca2d75597f..44fab49bbf 100644 --- a/x/observer/types/message_crosschain_flags_test.go +++ b/x/observer/types/message_crosschain_flags_test.go @@ -4,7 +4,7 @@ import ( "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/observer/types" ) @@ -56,10 +56,10 @@ func TestMsgUpdateCrosschainFlags_ValidateBasic(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - assert.ErrorIs(t, err, tt.err) + require.ErrorIs(t, err, tt.err) return } - assert.NoError(t, err) + require.NoError(t, err) }) } } @@ -109,10 +109,10 @@ func TestGasPriceIncreaseFlags_Validate(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.gpf.Validate() if tt.errContains != "" { - assert.ErrorContains(t, err, tt.errContains) + require.ErrorContains(t, err, tt.errContains) return } - assert.NoError(t, err) + require.NoError(t, err) }) } } @@ -227,7 +227,7 @@ func TestMsgUpdateCrosschainFlags_GetRequiredGroup(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - assert.Equal(t, tt.want, tt.msg.GetRequiredGroup()) + require.Equal(t, tt.want, tt.msg.GetRequiredGroup()) }) } } diff --git a/x/observer/types/message_remove_chain_params_test.go b/x/observer/types/message_remove_chain_params_test.go index acc20ca9dd..10d5a4c777 100644 --- a/x/observer/types/message_remove_chain_params_test.go +++ b/x/observer/types/message_remove_chain_params_test.go @@ -4,7 +4,7 @@ import ( "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/observer/types" @@ -45,10 +45,10 @@ func TestMsgRemoveChainParams_ValidateBasic(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - assert.ErrorIs(t, err, tt.err) + require.ErrorIs(t, err, tt.err) return } - assert.NoError(t, err) + require.NoError(t, err) }) } } diff --git a/x/observer/types/message_set_ballot_threshold_test.go b/x/observer/types/message_set_ballot_threshold_test.go index 814dfd5646..6e797800c1 100644 --- a/x/observer/types/message_set_ballot_threshold_test.go +++ b/x/observer/types/message_set_ballot_threshold_test.go @@ -25,10 +25,10 @@ package types // t.Run(tt.name, func(t *testing.T) { // err := tt.msg.ValidateBasic() // if tt.err != nil { -// assert.ErrorIs(t, err, tt.err) +// require.ErrorIs(t, err, tt.err) // return // } -// assert.NoError(t, err) +// require.NoError(t, err) // }) // } //} diff --git a/x/observer/types/message_update_chain_params_test.go b/x/observer/types/message_update_chain_params_test.go index 5c979dda08..3f3efc4e2f 100644 --- a/x/observer/types/message_update_chain_params_test.go +++ b/x/observer/types/message_update_chain_params_test.go @@ -4,7 +4,7 @@ import ( "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/observer/types" @@ -44,10 +44,10 @@ func TestMsgUpdateChainParams_ValidateBasic(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - assert.ErrorIs(t, err, tt.err) + require.ErrorIs(t, err, tt.err) return } - assert.NoError(t, err) + require.NoError(t, err) }) } } diff --git a/x/observer/types/message_update_keygen_test.go b/x/observer/types/message_update_keygen_test.go index 13213b9a98..b7ad69741c 100644 --- a/x/observer/types/message_update_keygen_test.go +++ b/x/observer/types/message_update_keygen_test.go @@ -4,7 +4,7 @@ import ( "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/observer/types" ) @@ -32,10 +32,10 @@ func TestMsgUpdateKeygen_ValidateBasic(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - assert.ErrorIs(t, err, tt.err) + require.ErrorIs(t, err, tt.err) return } - assert.NoError(t, err) + require.NoError(t, err) }) } } diff --git a/x/observer/types/message_update_observer_test.go b/x/observer/types/message_update_observer_test.go index e438f6d9db..0cff6bd25b 100644 --- a/x/observer/types/message_update_observer_test.go +++ b/x/observer/types/message_update_observer_test.go @@ -4,7 +4,7 @@ import ( "testing" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/testutil/sample" "github.com/zeta-chain/zetacore/x/observer/types" ) @@ -79,10 +79,10 @@ func TestNewMsgUpdateObserver(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := tt.msg.ValidateBasic() if tt.err != nil { - assert.ErrorIs(t, err, tt.err) + require.ErrorIs(t, err, tt.err) return } - assert.NoError(t, err) + require.NoError(t, err) }) } } diff --git a/zetaclient/btc_signer_test.go b/zetaclient/btc_signer_test.go index 75d039664b..d848126b8b 100644 --- a/zetaclient/btc_signer_test.go +++ b/zetaclient/btc_signer_test.go @@ -19,7 +19,7 @@ import ( "github.com/btcsuite/btcutil" "github.com/ethereum/go-ethereum/crypto" "github.com/rs/zerolog" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" "github.com/zeta-chain/zetacore/zetaclient/config" . "gopkg.in/check.v1" @@ -232,13 +232,13 @@ func (s *BTCSignerSuite) TestP2WPH(c *C) { func generateKeyPair(t *testing.T, net *chaincfg.Params) (*btcec.PrivateKey, []byte) { privateKey, err := btcec.NewPrivateKey(btcec.S256()) - assert.Nil(t, err) + require.Nil(t, err) pubKeyHash := btcutil.Hash160(privateKey.PubKey().SerializeCompressed()) addr, err := btcutil.NewAddressWitnessPubKeyHash(pubKeyHash, net) - assert.Nil(t, err) + require.Nil(t, err) //fmt.Printf("New address: %s\n", addr.EncodeAddress()) pkScript, err := payToWitnessPubKeyHashScript(addr.WitnessProgram()) - assert.Nil(t, err) + require.Nil(t, err) return privateKey, pkScript } @@ -246,11 +246,11 @@ func addTxInputs(t *testing.T, tx *wire.MsgTx, txids []string) { preTxSize := tx.SerializeSize() for _, txid := range txids { hash, err := chainhash.NewHashFromStr(txid) - assert.Nil(t, err) + require.Nil(t, err) outpoint := wire.NewOutPoint(hash, uint32(rand.Intn(100))) txIn := wire.NewTxIn(outpoint, nil, nil) tx.AddTxIn(txIn) - assert.Equal(t, bytesPerInput, tx.SerializeSize()-preTxSize) + require.Equal(t, bytesPerInput, tx.SerializeSize()-preTxSize) //fmt.Printf("tx size: %d, input %d size: %d\n", tx.SerializeSize(), i, tx.SerializeSize()-preTxSize) preTxSize = tx.SerializeSize() } @@ -263,7 +263,7 @@ func addTxOutputs(t *testing.T, tx *wire.MsgTx, payerScript, payeeScript []byte) value1 := int64(1 + rand.Intn(100000000)) txOut1 := wire.NewTxOut(value1, payerScript) tx.AddTxOut(txOut1) - assert.Equal(t, bytesPerOutput, tx.SerializeSize()-preTxSize) + require.Equal(t, bytesPerOutput, tx.SerializeSize()-preTxSize) //fmt.Printf("tx size: %d, output 1: %d\n", tx.SerializeSize(), tx.SerializeSize()-preTxSize) preTxSize = tx.SerializeSize() @@ -271,7 +271,7 @@ func addTxOutputs(t *testing.T, tx *wire.MsgTx, payerScript, payeeScript []byte) value2 := int64(1 + rand.Intn(100000000)) txOut2 := wire.NewTxOut(value2, payeeScript) tx.AddTxOut(txOut2) - assert.Equal(t, bytesPerOutput, tx.SerializeSize()-preTxSize) + require.Equal(t, bytesPerOutput, tx.SerializeSize()-preTxSize) //fmt.Printf("tx size: %d, output 2: %d\n", tx.SerializeSize(), tx.SerializeSize()-preTxSize) preTxSize = tx.SerializeSize() @@ -279,7 +279,7 @@ func addTxOutputs(t *testing.T, tx *wire.MsgTx, payerScript, payeeScript []byte) value3 := int64(1 + rand.Intn(100000000)) txOut3 := wire.NewTxOut(value3, payeeScript) tx.AddTxOut(txOut3) - assert.Equal(t, bytesPerOutput, tx.SerializeSize()-preTxSize) + require.Equal(t, bytesPerOutput, tx.SerializeSize()-preTxSize) //fmt.Printf("tx size: %d, output 3: %d\n", tx.SerializeSize(), tx.SerializeSize()-preTxSize) } @@ -289,9 +289,9 @@ func signTx(t *testing.T, tx *wire.MsgTx, payerScript []byte, privateKey *btcec. for ix := range tx.TxIn { amount := int64(1 + rand.Intn(100000000)) witnessHash, err := txscript.CalcWitnessSigHash(payerScript, sigHashes, txscript.SigHashAll, tx, ix, amount) - assert.Nil(t, err) + require.Nil(t, err) sig, err := privateKey.Sign(witnessHash) - assert.Nil(t, err) + require.Nil(t, err) pkCompressed := privateKey.PubKey().SerializeCompressed() txWitness := wire.TxWitness{append(sig.Serialize(), byte(txscript.SigHashAll)), pkCompressed} @@ -300,11 +300,11 @@ func signTx(t *testing.T, tx *wire.MsgTx, payerScript []byte, privateKey *btcec. //fmt.Printf("tx size: %d, witness %d: %d\n", tx.SerializeSize(), ix+1, tx.SerializeSize()-preTxSize) if ix == 0 { bytesIncur := bytes1stWitness + len(tx.TxIn) - 1 // e.g., 130 bytes for a 21-input tx - assert.True(t, tx.SerializeSize()-preTxSize >= bytesIncur-5) - assert.True(t, tx.SerializeSize()-preTxSize <= bytesIncur+5) + require.True(t, tx.SerializeSize()-preTxSize >= bytesIncur-5) + require.True(t, tx.SerializeSize()-preTxSize <= bytesIncur+5) } else { - assert.True(t, tx.SerializeSize()-preTxSize >= bytesPerWitness-5) - assert.True(t, tx.SerializeSize()-preTxSize <= bytesPerWitness+5) + require.True(t, tx.SerializeSize()-preTxSize >= bytesPerWitness-5) + require.True(t, tx.SerializeSize()-preTxSize <= bytesPerWitness+5) } preTxSize = tx.SerializeSize() } @@ -335,8 +335,8 @@ func TestP2WPHSize2In3Out(t *testing.T) { // #nosec G701 always positive vBytes := uint64(blockchain.GetTransactionWeight(btcutil.NewTx(tx)) / blockchain.WitnessScaleFactor) vBytesEstimated := EstimateSegWitTxSize(uint64(len(utxosTxids)), 3) - assert.Equal(t, vBytes, vBytesEstimated) - assert.Equal(t, vBytes, outTxBytesMin) + require.Equal(t, vBytes, vBytesEstimated) + require.Equal(t, vBytes, outTxBytesMin) } func TestP2WPHSize21In3Out(t *testing.T) { @@ -359,11 +359,11 @@ func TestP2WPHSize21In3Out(t *testing.T) { vError := uint64(21 / 4) // 5 vBytes error tolerance vBytes := uint64(blockchain.GetTransactionWeight(btcutil.NewTx(tx)) / blockchain.WitnessScaleFactor) vBytesEstimated := EstimateSegWitTxSize(uint64(len(exampleTxids)), 3) - assert.Equal(t, vBytesEstimated, outTxBytesMax) + require.Equal(t, vBytesEstimated, outTxBytesMax) if vBytes > vBytesEstimated { - assert.True(t, vBytes-vBytesEstimated <= vError) + require.True(t, vBytes-vBytesEstimated <= vError) } else { - assert.True(t, vBytesEstimated-vBytes <= vError) + require.True(t, vBytesEstimated-vBytes <= vError) } } @@ -389,10 +389,10 @@ func TestP2WPHSizeXIn3Out(t *testing.T) { vBytes := uint64(blockchain.GetTransactionWeight(btcutil.NewTx(tx)) / blockchain.WitnessScaleFactor) vBytesEstimated := EstimateSegWitTxSize(uint64(len(exampleTxids[:x])), 3) if vBytes > vBytesEstimated { - assert.True(t, vBytes-vBytesEstimated <= vError) + require.True(t, vBytes-vBytesEstimated <= vError) //fmt.Printf("%d error percentage: %.2f%%\n", float64(vBytes-vBytesEstimated)/float64(vBytes)*100) } else { - assert.True(t, vBytesEstimated-vBytes <= vError) + require.True(t, vBytesEstimated-vBytes <= vError) //fmt.Printf("error percentage: %.2f%%\n", float64(vBytesEstimated-vBytes)/float64(vBytes)*100) } } @@ -400,27 +400,27 @@ func TestP2WPHSizeXIn3Out(t *testing.T) { func TestP2WPHSizeBreakdown(t *testing.T) { txSize2In3Out := EstimateSegWitTxSize(2, 3) - assert.Equal(t, outTxBytesMin, txSize2In3Out) + require.Equal(t, outTxBytesMin, txSize2In3Out) sz := EstimateSegWitTxSize(1, 1) fmt.Printf("1 input, 1 output: %d\n", sz) txSizeDepositor := SegWitTxSizeDepositor() - assert.Equal(t, uint64(68), txSizeDepositor) + require.Equal(t, uint64(68), txSizeDepositor) txSizeWithdrawer := SegWitTxSizeWithdrawer() - assert.Equal(t, uint64(171), txSizeWithdrawer) - assert.Equal(t, txSize2In3Out, txSizeDepositor+txSizeWithdrawer) // 239 = 68 + 171 + require.Equal(t, uint64(171), txSizeWithdrawer) + require.Equal(t, txSize2In3Out, txSizeDepositor+txSizeWithdrawer) // 239 = 68 + 171 depositFee := DepositorFee(20) - assert.Equal(t, depositFee, 0.00001360) + require.Equal(t, depositFee, 0.00001360) } // helper function to create a new BitcoinChainClient func createTestClient(t *testing.T) *BitcoinChainClient { skHex := "7b8507ba117e069f4a3f456f505276084f8c92aee86ac78ae37b4d1801d35fa8" privateKey, err := crypto.HexToECDSA(skHex) - assert.Nil(t, err) + require.Nil(t, err) tss := TestSigner{ PrivKey: privateKey, } @@ -469,85 +469,85 @@ func TestSelectUTXOs(t *testing.T) { // input: utxoCap = 5, amount = 0.01, nonce = 0 // output: [0.01], 0.01 result, amount, _, _, err := ob.SelectUTXOs(0.01, 5, 0, math.MaxUint16, true) - assert.Nil(t, err) - assert.Equal(t, 0.01, amount) - assert.Equal(t, ob.utxos[0:1], result) + require.Nil(t, err) + require.Equal(t, 0.01, amount) + require.Equal(t, ob.utxos[0:1], result) // Case2: nonce = 1, must FAIL and wait for previous transaction to be mined // input: utxoCap = 5, amount = 0.5, nonce = 1 // output: error result, amount, _, _, err = ob.SelectUTXOs(0.5, 5, 1, math.MaxUint16, true) - assert.NotNil(t, err) - assert.Nil(t, result) - assert.Zero(t, amount) - assert.Equal(t, "getOutTxidByNonce: cannot find outTx txid for nonce 0", err.Error()) + require.NotNil(t, err) + require.Nil(t, result) + require.Zero(t, amount) + require.Equal(t, "getOutTxidByNonce: cannot find outTx txid for nonce 0", err.Error()) mineTxNSetNonceMark(ob, 0, dummyTxID, -1) // mine a transaction and set nonce-mark utxo for nonce 0 // Case3: nonce = 1, should pass now // input: utxoCap = 5, amount = 0.5, nonce = 1 // output: [0.00002, 0.01, 0.12, 0.18, 0.24], 0.55002 result, amount, _, _, err = ob.SelectUTXOs(0.5, 5, 1, math.MaxUint16, true) - assert.Nil(t, err) - assert.Equal(t, 0.55002, amount) - assert.Equal(t, ob.utxos[0:5], result) + require.Nil(t, err) + require.Equal(t, 0.55002, amount) + require.Equal(t, ob.utxos[0:5], result) mineTxNSetNonceMark(ob, 1, dummyTxID, 0) // mine a transaction and set nonce-mark utxo for nonce 1 // Case4: // input: utxoCap = 5, amount = 1.0, nonce = 2 // output: [0.00002001, 0.01, 0.12, 0.18, 0.24, 0.5], 1.05002001 result, amount, _, _, err = ob.SelectUTXOs(1.0, 5, 2, math.MaxUint16, true) - assert.Nil(t, err) - assert.InEpsilon(t, 1.05002001, amount, 1e-8) - assert.Equal(t, ob.utxos[0:6], result) + require.Nil(t, err) + require.InEpsilon(t, 1.05002001, amount, 1e-8) + require.Equal(t, ob.utxos[0:6], result) mineTxNSetNonceMark(ob, 2, dummyTxID, 0) // mine a transaction and set nonce-mark utxo for nonce 2 // Case5: should include nonce-mark utxo on the LEFT // input: utxoCap = 5, amount = 8.05, nonce = 3 // output: [0.00002002, 0.24, 0.5, 1.26, 2.97, 3.28], 8.25002002 result, amount, _, _, err = ob.SelectUTXOs(8.05, 5, 3, math.MaxUint16, true) - assert.Nil(t, err) - assert.InEpsilon(t, 8.25002002, amount, 1e-8) + require.Nil(t, err) + require.InEpsilon(t, 8.25002002, amount, 1e-8) expected := append([]btcjson.ListUnspentResult{ob.utxos[0]}, ob.utxos[4:9]...) - assert.Equal(t, expected, result) + require.Equal(t, expected, result) mineTxNSetNonceMark(ob, 24105431, dummyTxID, 0) // mine a transaction and set nonce-mark utxo for nonce 24105431 // Case6: should include nonce-mark utxo on the RIGHT // input: utxoCap = 5, amount = 0.503, nonce = 24105432 // output: [0.24107432, 0.01, 0.12, 0.18, 0.24], 0.55002002 result, amount, _, _, err = ob.SelectUTXOs(0.503, 5, 24105432, math.MaxUint16, true) - assert.Nil(t, err) - assert.InEpsilon(t, 0.79107431, amount, 1e-8) + require.Nil(t, err) + require.InEpsilon(t, 0.79107431, amount, 1e-8) expected = append([]btcjson.ListUnspentResult{ob.utxos[4]}, ob.utxos[0:4]...) - assert.Equal(t, expected, result) + require.Equal(t, expected, result) mineTxNSetNonceMark(ob, 24105432, dummyTxID, 4) // mine a transaction and set nonce-mark utxo for nonce 24105432 // Case7: should include nonce-mark utxo in the MIDDLE // input: utxoCap = 5, amount = 1.0, nonce = 24105433 // output: [0.24107432, 0.12, 0.18, 0.24, 0.5], 1.28107432 result, amount, _, _, err = ob.SelectUTXOs(1.0, 5, 24105433, math.MaxUint16, true) - assert.Nil(t, err) - assert.InEpsilon(t, 1.28107432, amount, 1e-8) + require.Nil(t, err) + require.InEpsilon(t, 1.28107432, amount, 1e-8) expected = append([]btcjson.ListUnspentResult{ob.utxos[4]}, ob.utxos[1:4]...) expected = append(expected, ob.utxos[5]) - assert.Equal(t, expected, result) + require.Equal(t, expected, result) // Case8: should work with maximum amount // input: utxoCap = 5, amount = 16.03 // output: [0.24107432, 1.26, 2.97, 3.28, 5.16, 8.72], 21.63107432 result, amount, _, _, err = ob.SelectUTXOs(16.03, 5, 24105433, math.MaxUint16, true) - assert.Nil(t, err) - assert.InEpsilon(t, 21.63107432, amount, 1e-8) + require.Nil(t, err) + require.InEpsilon(t, 21.63107432, amount, 1e-8) expected = append([]btcjson.ListUnspentResult{ob.utxos[4]}, ob.utxos[6:11]...) - assert.Equal(t, expected, result) + require.Equal(t, expected, result) // Case9: must FAIL due to insufficient funds // input: utxoCap = 5, amount = 21.64 // output: error result, amount, _, _, err = ob.SelectUTXOs(21.64, 5, 24105433, math.MaxUint16, true) - assert.NotNil(t, err) - assert.Nil(t, result) - assert.Zero(t, amount) - assert.Equal(t, "SelectUTXOs: not enough btc in reserve - available : 21.63107432 , tx amount : 21.64", err.Error()) + require.NotNil(t, err) + require.Nil(t, result) + require.Zero(t, amount) + require.Equal(t, "SelectUTXOs: not enough btc in reserve - available : 21.63107432 , tx amount : 21.64", err.Error()) } func TestUTXOConsolidation(t *testing.T) { @@ -560,11 +560,11 @@ func TestUTXOConsolidation(t *testing.T) { // input: utxoCap = 10, amount = 0.01, nonce = 1, rank = 10 // output: [0.00002, 0.01], 0.01002 result, amount, clsdtUtxo, clsdtValue, err := ob.SelectUTXOs(0.01, 10, 1, 10, true) - assert.Nil(t, err) - assert.Equal(t, 0.01002, amount) - assert.Equal(t, ob.utxos[0:2], result) - assert.Equal(t, uint16(0), clsdtUtxo) - assert.Equal(t, 0.0, clsdtValue) + require.Nil(t, err) + require.Equal(t, 0.01002, amount) + require.Equal(t, ob.utxos[0:2], result) + require.Equal(t, uint16(0), clsdtUtxo) + require.Equal(t, 0.0, clsdtValue) }) t.Run("should consolidate 1 utxo", func(t *testing.T) { @@ -574,11 +574,11 @@ func TestUTXOConsolidation(t *testing.T) { // input: utxoCap = 9, amount = 0.01, nonce = 1, rank = 9 // output: [0.00002, 0.01, 0.12], 0.13002 result, amount, clsdtUtxo, clsdtValue, err := ob.SelectUTXOs(0.01, 9, 1, 9, true) - assert.Nil(t, err) - assert.Equal(t, 0.13002, amount) - assert.Equal(t, ob.utxos[0:3], result) - assert.Equal(t, uint16(1), clsdtUtxo) - assert.Equal(t, 0.12, clsdtValue) + require.Nil(t, err) + require.Equal(t, 0.13002, amount) + require.Equal(t, ob.utxos[0:3], result) + require.Equal(t, uint16(1), clsdtUtxo) + require.Equal(t, 0.12, clsdtValue) }) t.Run("should consolidate 3 utxos", func(t *testing.T) { @@ -588,16 +588,16 @@ func TestUTXOConsolidation(t *testing.T) { // input: utxoCap = 5, amount = 0.01, nonce = 0, rank = 5 // output: [0.00002, 0.014, 1.26, 0.5, 0.2], 2.01002 result, amount, clsdtUtxo, clsdtValue, err := ob.SelectUTXOs(0.01, 5, 1, 5, true) - assert.Nil(t, err) - assert.Equal(t, 2.01002, amount) + require.Nil(t, err) + require.Equal(t, 2.01002, amount) expected := make([]btcjson.ListUnspentResult, 2) copy(expected, ob.utxos[0:2]) for i := 6; i >= 4; i-- { // append consolidated utxos in descending order expected = append(expected, ob.utxos[i]) } - assert.Equal(t, expected, result) - assert.Equal(t, uint16(3), clsdtUtxo) - assert.Equal(t, 2.0, clsdtValue) + require.Equal(t, expected, result) + require.Equal(t, uint16(3), clsdtUtxo) + require.Equal(t, 2.0, clsdtValue) }) t.Run("should consolidate all utxos using rank 1", func(t *testing.T) { @@ -607,16 +607,16 @@ func TestUTXOConsolidation(t *testing.T) { // input: utxoCap = 12, amount = 0.01, nonce = 0, rank = 1 // output: [0.00002, 0.01, 8.72, 5.16, 3.28, 2.97, 1.26, 0.5, 0.24, 0.18, 0.12], 22.44002 result, amount, clsdtUtxo, clsdtValue, err := ob.SelectUTXOs(0.01, 12, 1, 1, true) - assert.Nil(t, err) - assert.Equal(t, 22.44002, amount) + require.Nil(t, err) + require.Equal(t, 22.44002, amount) expected := make([]btcjson.ListUnspentResult, 2) copy(expected, ob.utxos[0:2]) for i := 10; i >= 2; i-- { // append consolidated utxos in descending order expected = append(expected, ob.utxos[i]) } - assert.Equal(t, expected, result) - assert.Equal(t, uint16(9), clsdtUtxo) - assert.Equal(t, 22.43, clsdtValue) + require.Equal(t, expected, result) + require.Equal(t, uint16(9), clsdtUtxo) + require.Equal(t, 22.43, clsdtValue) }) t.Run("should consolidate 3 utxos sparse", func(t *testing.T) { @@ -626,15 +626,15 @@ func TestUTXOConsolidation(t *testing.T) { // input: utxoCap = 5, amount = 0.13, nonce = 24105432, rank = 5 // output: [0.24107431, 0.01, 0.12, 1.26, 0.5, 0.24], 2.37107431 result, amount, clsdtUtxo, clsdtValue, err := ob.SelectUTXOs(0.13, 5, 24105432, 5, true) - assert.Nil(t, err) - assert.InEpsilon(t, 2.37107431, amount, 1e-8) + require.Nil(t, err) + require.InEpsilon(t, 2.37107431, amount, 1e-8) expected := append([]btcjson.ListUnspentResult{ob.utxos[4]}, ob.utxos[0:2]...) expected = append(expected, ob.utxos[6]) expected = append(expected, ob.utxos[5]) expected = append(expected, ob.utxos[3]) - assert.Equal(t, expected, result) - assert.Equal(t, uint16(3), clsdtUtxo) - assert.Equal(t, 2.0, clsdtValue) + require.Equal(t, expected, result) + require.Equal(t, uint16(3), clsdtUtxo) + require.Equal(t, 2.0, clsdtValue) }) t.Run("should consolidate all utxos sparse", func(t *testing.T) { @@ -644,16 +644,16 @@ func TestUTXOConsolidation(t *testing.T) { // input: utxoCap = 12, amount = 0.13, nonce = 24105432, rank = 1 // output: [0.24107431, 0.01, 0.12, 8.72, 5.16, 3.28, 2.97, 1.26, 0.5, 0.24, 0.18], 22.68107431 result, amount, clsdtUtxo, clsdtValue, err := ob.SelectUTXOs(0.13, 12, 24105432, 1, true) - assert.Nil(t, err) - assert.InEpsilon(t, 22.68107431, amount, 1e-8) + require.Nil(t, err) + require.InEpsilon(t, 22.68107431, amount, 1e-8) expected := append([]btcjson.ListUnspentResult{ob.utxos[4]}, ob.utxos[0:2]...) for i := 10; i >= 5; i-- { // append consolidated utxos in descending order expected = append(expected, ob.utxos[i]) } expected = append(expected, ob.utxos[3]) expected = append(expected, ob.utxos[2]) - assert.Equal(t, expected, result) - assert.Equal(t, uint16(8), clsdtUtxo) - assert.Equal(t, 22.31, clsdtValue) + require.Equal(t, expected, result) + require.Equal(t, uint16(8), clsdtUtxo) + require.Equal(t, 22.31, clsdtValue) }) } diff --git a/zetaclient/hsm/hsm_signer_test.go b/zetaclient/hsm/hsm_signer_test.go index 2c35f8b625..5c7ba38099 100644 --- a/zetaclient/hsm/hsm_signer_test.go +++ b/zetaclient/hsm/hsm_signer_test.go @@ -12,7 +12,7 @@ import ( btcsecp256k1 "github.com/btcsuite/btcd/btcec" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" keystone "github.com/zeta-chain/keystone/keys" ) @@ -26,20 +26,20 @@ func TestSignSecp256k1(t *testing.T) { //Generate random label for key label, err := randomBytes(16) - assert.NoError(t, err) + require.NoError(t, err) //Generate key key, err := GenerateKey(string(label), keystone.KEYGEN_SECP256K1, config) - assert.NoError(t, err) - assert.NotNil(t, key) + require.NoError(t, err) + require.NotNil(t, key) //Create sample message msg := []byte("Signing this plaintext tells me what exactly?") signature, err := Sign(config, msg, string(label)) - assert.NoError(t, err) - assert.NotNil(t, signature) - assert.Equal(t, key.KeyType(), keystone.KEYGEN_SECP256K1) + require.NoError(t, err) + require.NotNil(t, signature) + require.Equal(t, key.KeyType(), keystone.KEYGEN_SECP256K1) pubkey := key.PubKey() secp256k1key := pubkey.(*secp256k1.PubKey) @@ -57,7 +57,7 @@ func TestSignSecp256k1(t *testing.T) { log.Printf("Address from HSM: %v, PubKey from HSM: %v", address, pubKey) err = key.Delete() - assert.NoError(t, err) + require.NoError(t, err) } func randomBytes(n int) ([]byte, error) { diff --git a/zetaclient/tss_signer_test.go b/zetaclient/tss_signer_test.go index 3fffc9277d..50ace51c14 100644 --- a/zetaclient/tss_signer_test.go +++ b/zetaclient/tss_signer_test.go @@ -7,7 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/testutil/testdata" "github.com/rs/zerolog" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/common" "github.com/zeta-chain/zetacore/common/cosmos" ) @@ -34,17 +34,17 @@ func Test_LoadTssFilesFromDirectory(t *testing.T) { for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { tempdir, err := os.MkdirTemp("", "test-tss") - assert.NoError(t, err) + require.NoError(t, err) err = GenerateKeyshareFiles(tc.n, tempdir) - assert.NoError(t, err) + require.NoError(t, err) tss := TSS{ logger: zerolog.New(os.Stdout), Keys: map[string]*TSSKey{}, CurrentPubkey: "", } err = tss.LoadTssFilesFromDirectory(tempdir) - assert.NoError(t, err) - assert.Equal(t, tc.n, len(tss.Keys)) + require.NoError(t, err) + require.Equal(t, tc.n, len(tss.Keys)) }) } } diff --git a/zetaclient/utils_test.go b/zetaclient/utils_test.go index 994c562bf1..98355e82ac 100644 --- a/zetaclient/utils_test.go +++ b/zetaclient/utils_test.go @@ -6,7 +6,7 @@ import ( ethcommon "github.com/ethereum/go-ethereum/common" ethtypes "github.com/ethereum/go-ethereum/core/types" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestCheckEvmTxLog(t *testing.T) { @@ -92,10 +92,10 @@ func TestCheckEvmTxLog(t *testing.T) { TopicsZetaSent, ) if tt.fail { - assert.Error(t, err) + require.Error(t, err) return } else { - assert.NoError(t, err) + require.NoError(t, err) } }) } diff --git a/zetaclient/zeta_supply_checker_test.go b/zetaclient/zeta_supply_checker_test.go index 020477ccd4..a8a92b958e 100644 --- a/zetaclient/zeta_supply_checker_test.go +++ b/zetaclient/zeta_supply_checker_test.go @@ -6,7 +6,7 @@ import ( sdkmath "cosmossdk.io/math" "github.com/rs/zerolog" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/zetaclient" ) @@ -26,7 +26,7 @@ func TestZetaSupplyChecker_ValidateZetaSupply(t *testing.T) { externalChainTotalSupply sdkmath.Int zetaTokenSupplyOnNode sdkmath.Int ethLockedAmount sdkmath.Int - validate assert.BoolAssertionFunc + validate require.BoolAssertionFunc }{ { name: "1 zeta cctx in progress", @@ -36,8 +36,8 @@ func TestZetaSupplyChecker_ValidateZetaSupply(t *testing.T) { genesisAmounts: MustNewIntFromString("1000000000000000000"), zetaTokenSupplyOnNode: MustNewIntFromString("1000000000000000000"), ethLockedAmount: MustNewIntFromString("10000000000000000000"), - validate: func(t assert.TestingT, b bool, i ...interface{}) bool { - return assert.True(t, b, i...) + validate: func(t require.TestingT, b bool, i ...interface{}) { + require.True(t, b, i...) }, }, // Todo add more scenarios From bf41f4f32c1ca9a132aa3c259803cdc62161296d Mon Sep 17 00:00:00 2001 From: Tanmay Date: Mon, 12 Feb 2024 02:13:50 -0500 Subject: [PATCH 13/13] use require for rpc folder --- rpc/ethereum/pubsub/pubsub_test.go | 22 +++++++++++----------- rpc/types/block_test.go | 30 +++++++++++++++--------------- rpc/types/events_test.go | 18 +++++++++--------- server/config/config_test.go | 8 ++++---- 4 files changed, 39 insertions(+), 39 deletions(-) diff --git a/rpc/ethereum/pubsub/pubsub_test.go b/rpc/ethereum/pubsub/pubsub_test.go index 6788f65259..9f5fe8d2e3 100644 --- a/rpc/ethereum/pubsub/pubsub_test.go +++ b/rpc/ethereum/pubsub/pubsub_test.go @@ -7,24 +7,24 @@ import ( "testing" "time" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" coretypes "github.com/tendermint/tendermint/rpc/core/types" ) func TestAddTopic(t *testing.T) { q := NewEventBus() err := q.AddTopic("kek", make(<-chan coretypes.ResultEvent)) - assert.NoError(t, err) + require.NoError(t, err) err = q.AddTopic("lol", make(<-chan coretypes.ResultEvent)) - assert.NoError(t, err) + require.NoError(t, err) err = q.AddTopic("lol", make(<-chan coretypes.ResultEvent)) - assert.Error(t, err) + require.Error(t, err) topics := q.Topics() sort.Strings(topics) - assert.EqualValues(t, []string{"kek", "lol"}, topics) + require.EqualValues(t, []string{"kek", "lol"}, topics) } func TestSubscribe(t *testing.T) { @@ -38,13 +38,13 @@ func TestSubscribe(t *testing.T) { q.AddTopic("lol", lolSrc) kekSubC, _, err := q.Subscribe("kek") - assert.NoError(t, err) + require.NoError(t, err) lolSubC, _, err := q.Subscribe("lol") - assert.NoError(t, err) + require.NoError(t, err) lol2SubC, _, err := q.Subscribe("lol") - assert.NoError(t, err) + require.NoError(t, err) wg := new(sync.WaitGroup) wg.Add(4) @@ -54,21 +54,21 @@ func TestSubscribe(t *testing.T) { defer wg.Done() msg := <-kekSubC log.Println("kek:", msg) - assert.EqualValues(t, emptyMsg, msg) + require.EqualValues(t, emptyMsg, msg) }() go func() { defer wg.Done() msg := <-lolSubC log.Println("lol:", msg) - assert.EqualValues(t, emptyMsg, msg) + require.EqualValues(t, emptyMsg, msg) }() go func() { defer wg.Done() msg := <-lol2SubC log.Println("lol2:", msg) - assert.EqualValues(t, emptyMsg, msg) + require.EqualValues(t, emptyMsg, msg) }() go func() { diff --git a/rpc/types/block_test.go b/rpc/types/block_test.go index 6fd0c9ecd8..1cbb11f61e 100644 --- a/rpc/types/block_test.go +++ b/rpc/types/block_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/ethereum/go-ethereum/common" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestUnmarshalBlockNumberOrHash(t *testing.T) { @@ -21,8 +21,8 @@ func TestUnmarshalBlockNumberOrHash(t *testing.T) { "JSON input with block hash", []byte("{\"blockHash\": \"0x579917054e325746fda5c3ee431d73d26255bc4e10b51163862368629ae19739\"}"), func() { - assert.Equal(t, *bnh.BlockHash, common.HexToHash("0x579917054e325746fda5c3ee431d73d26255bc4e10b51163862368629ae19739")) - assert.Nil(t, bnh.BlockNumber) + require.Equal(t, *bnh.BlockHash, common.HexToHash("0x579917054e325746fda5c3ee431d73d26255bc4e10b51163862368629ae19739")) + require.Nil(t, bnh.BlockNumber) }, true, }, @@ -30,8 +30,8 @@ func TestUnmarshalBlockNumberOrHash(t *testing.T) { "JSON input with block number", []byte("{\"blockNumber\": \"0x35\"}"), func() { - assert.Equal(t, *bnh.BlockNumber, BlockNumber(0x35)) - assert.Nil(t, bnh.BlockHash) + require.Equal(t, *bnh.BlockNumber, BlockNumber(0x35)) + require.Nil(t, bnh.BlockHash) }, true, }, @@ -39,8 +39,8 @@ func TestUnmarshalBlockNumberOrHash(t *testing.T) { "JSON input with block number latest", []byte("{\"blockNumber\": \"latest\"}"), func() { - assert.Equal(t, *bnh.BlockNumber, EthLatestBlockNumber) - assert.Nil(t, bnh.BlockHash) + require.Equal(t, *bnh.BlockNumber, EthLatestBlockNumber) + require.Nil(t, bnh.BlockHash) }, true, }, @@ -55,8 +55,8 @@ func TestUnmarshalBlockNumberOrHash(t *testing.T) { "String input with block hash", []byte("\"0x579917054e325746fda5c3ee431d73d26255bc4e10b51163862368629ae19739\""), func() { - assert.Equal(t, *bnh.BlockHash, common.HexToHash("0x579917054e325746fda5c3ee431d73d26255bc4e10b51163862368629ae19739")) - assert.Nil(t, bnh.BlockNumber) + require.Equal(t, *bnh.BlockHash, common.HexToHash("0x579917054e325746fda5c3ee431d73d26255bc4e10b51163862368629ae19739")) + require.Nil(t, bnh.BlockNumber) }, true, }, @@ -64,8 +64,8 @@ func TestUnmarshalBlockNumberOrHash(t *testing.T) { "String input with block number", []byte("\"0x35\""), func() { - assert.Equal(t, *bnh.BlockNumber, BlockNumber(0x35)) - assert.Nil(t, bnh.BlockHash) + require.Equal(t, *bnh.BlockNumber, BlockNumber(0x35)) + require.Nil(t, bnh.BlockHash) }, true, }, @@ -73,8 +73,8 @@ func TestUnmarshalBlockNumberOrHash(t *testing.T) { "String input with block number latest", []byte("\"latest\""), func() { - assert.Equal(t, *bnh.BlockNumber, EthLatestBlockNumber) - assert.Nil(t, bnh.BlockHash) + require.Equal(t, *bnh.BlockNumber, EthLatestBlockNumber) + require.Nil(t, bnh.BlockHash) }, true, }, @@ -94,9 +94,9 @@ func TestUnmarshalBlockNumberOrHash(t *testing.T) { err := bnh.UnmarshalJSON(tc.input) tc.malleate() if tc.expPass { - assert.NoError(t, err) + require.NoError(t, err) } else { - assert.Error(t, err) + require.Error(t, err) } } } diff --git a/rpc/types/events_test.go b/rpc/types/events_test.go index e76a611b96..f25f4489ae 100644 --- a/rpc/types/events_test.go +++ b/rpc/types/events_test.go @@ -6,7 +6,7 @@ import ( "github.com/ethereum/go-ethereum/common" evmtypes "github.com/evmos/ethermint/x/evm/types" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" ) @@ -232,19 +232,19 @@ func TestParseTxResult(t *testing.T) { t.Run(tc.name, func(t *testing.T) { parsed, err := ParseTxResult(&tc.response, nil) if tc.expTxs == nil { - assert.Error(t, err) + require.Error(t, err) } else { - assert.NoError(t, err) + require.NoError(t, err) for msgIndex, expTx := range tc.expTxs { - assert.Equal(t, expTx, parsed.GetTxByMsgIndex(msgIndex)) - assert.Equal(t, expTx, parsed.GetTxByHash(expTx.Hash)) - assert.Equal(t, expTx, parsed.GetTxByTxIndex(int(expTx.EthTxIndex))) + require.Equal(t, expTx, parsed.GetTxByMsgIndex(msgIndex)) + require.Equal(t, expTx, parsed.GetTxByHash(expTx.Hash)) + require.Equal(t, expTx, parsed.GetTxByTxIndex(int(expTx.EthTxIndex))) } // non-exists tx hash - assert.Nil(t, parsed.GetTxByHash(common.Hash{})) + require.Nil(t, parsed.GetTxByHash(common.Hash{})) // out of range - assert.Nil(t, parsed.GetTxByMsgIndex(len(tc.expTxs))) - assert.Nil(t, parsed.GetTxByTxIndex(99999999)) + require.Nil(t, parsed.GetTxByMsgIndex(len(tc.expTxs))) + require.Nil(t, parsed.GetTxByTxIndex(99999999)) } }) } diff --git a/server/config/config_test.go b/server/config/config_test.go index 3241594e48..9a19e3e997 100644 --- a/server/config/config_test.go +++ b/server/config/config_test.go @@ -3,12 +3,12 @@ package config import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestDefaultConfig(t *testing.T) { cfg := DefaultConfig() - assert.True(t, cfg.JSONRPC.Enable) - assert.Equal(t, cfg.JSONRPC.Address, DefaultJSONRPCAddress) - assert.Equal(t, cfg.JSONRPC.WsAddress, DefaultJSONRPCWsAddress) + require.True(t, cfg.JSONRPC.Enable) + require.Equal(t, cfg.JSONRPC.Address, DefaultJSONRPCAddress) + require.Equal(t, cfg.JSONRPC.WsAddress, DefaultJSONRPCWsAddress) }