Skip to content

Commit b90f0d9

Browse files
yihuangclaudehappy-otter
committed
fix: variable declarations in BeforeEach blocks
- Use short declaration operator (:=) in BeforeEach blocks instead of separate var declarations - Fix DepositEvent and WithdrawalEvent to use pointers: &werc20.DepositEvent{} - Fix ERC20 return type field access (Field1 instead of Balance, Name, Symbol, Decimals) - Remove unused crypto import from test_events.go 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> Co-Authored-By: Happy <[email protected]>
1 parent 17c90ed commit b90f0d9

File tree

5 files changed

+67
-72
lines changed

5 files changed

+67
-72
lines changed

tests/integration/precompiles/erc20/test_integration.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,27 +107,18 @@ func TestIntegrationTestSuite(t *testing.T, create network.CreateEvmApp, options
107107
// contractsData holds the addresses and ABIs for the different
108108
// contract instances that are subject to testing here.
109109
contractsData ContractsData
110-
111-
erc20MdCallerContract evmtypes.CompiledContract
112-
revertCallerContract evmtypes.CompiledContract
113-
erc20MinterV5Contract evmtypes.CompiledContract
114-
115-
execRevertedCheck testutil.LogCheckArgs
116-
failCheck testutil.LogCheckArgs
117-
passCheck testutil.LogCheckArgs
118110
)
119111

120112
BeforeEach(func() {
121113
is.SetupTest()
122114

123-
var err error
124-
erc20MdCallerContract, err = testdata.LoadERC20TestCaller()
115+
erc20MdCallerContract, err := testdata.LoadERC20TestCaller()
125116
Expect(err).ToNot(HaveOccurred(), "failed to load ERC20 allowance caller contract")
126117

127-
erc20MinterV5Contract, err = testdata.LoadERC20MinterV5Contract()
118+
erc20MinterV5Contract, err := testdata.LoadERC20MinterV5Contract()
128119
Expect(err).ToNot(HaveOccurred(), "failed to load ERC20 minter contract")
129120

130-
revertCallerContract, err = testdata.LoadERC20TestCaller()
121+
revertCallerContract, err := testdata.LoadERC20TestCaller()
131122
Expect(err).ToNot(HaveOccurred(), "failed to load ERC20 allowance caller contract")
132123

133124
sender := is.keyring.GetKey(0)

tests/integration/precompiles/slashing/test_integration.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ func TestPrecompileIntegrationTestSuite(t *testing.T, create network.CreateEvmAp
6464
BeforeEach(func() {
6565
s.SetupTest()
6666

67-
valAddr, err = sdk.ValAddressFromBech32(s.network.GetValidators()[0].GetOperator())
67+
valAddr, err := sdk.ValAddressFromBech32(s.network.GetValidators()[0].GetOperator())
6868
Expect(err).To(BeNil())
6969

7070
// send funds to the contract
71-
err := utils.FundAccountWithBaseDenom(s.factory, s.network, s.keyring.GetKey(0), contractAddr.Bytes(), math.NewInt(2e18))
71+
err = utils.FundAccountWithBaseDenom(s.factory, s.network, s.keyring.GetKey(0), contractAddr.Bytes(), math.NewInt(2e18))
7272
Expect(err).To(BeNil())
7373
Expect(s.network.NextBlock()).To(BeNil())
7474

tests/integration/precompiles/staking/test_integration.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,10 @@ func TestPrecompileIntegrationTestSuite(t *testing.T, create network.CreateEvmAp
6262
var s *PrecompileTestSuite
6363

6464
BeforeEach(func() {
65-
var err error
6665
s = NewPrecompileTestSuite(create, options...)
6766
s.SetupTest()
6867

69-
valAddr, err = sdk.ValAddressFromBech32(s.network.GetValidators()[0].GetOperator())
68+
valAddr, err := sdk.ValAddressFromBech32(s.network.GetValidators()[0].GetOperator())
7069
Expect(err).To(BeNil())
7170
valAddr2, err = sdk.ValAddressFromBech32(s.network.GetValidators()[1].GetOperator())
7271
Expect(err).To(BeNil())
@@ -1391,7 +1390,7 @@ func TestPrecompileIntegrationTestSuite(t *testing.T, create network.CreateEvmAp
13911390
s.SetupTest()
13921391
delegator := s.keyring.GetKey(0)
13931392

1394-
contractAddr, err = s.factory.DeployContract(
1393+
contractAddr, err := s.factory.DeployContract(
13951394
delegator.Priv,
13961395
evmtypes.EvmTxArgs{}, // NOTE: passing empty struct to use default values
13971396
testutiltypes.ContractDeploymentData{
@@ -1407,7 +1406,7 @@ func TestPrecompileIntegrationTestSuite(t *testing.T, create network.CreateEvmAp
14071406
Expect(s.network.NextBlock()).To(BeNil())
14081407

14091408
// Deploy StakingCallerTwo contract
1410-
contractTwoAddr, err = s.factory.DeployContract(
1409+
contractTwoAddr, err := s.factory.DeployContract(
14111410
delegator.Priv,
14121411
evmtypes.EvmTxArgs{}, // NOTE: passing empty struct to use default values
14131412
testutiltypes.ContractDeploymentData{
@@ -1418,7 +1417,7 @@ func TestPrecompileIntegrationTestSuite(t *testing.T, create network.CreateEvmAp
14181417
Expect(s.network.NextBlock()).To(BeNil())
14191418

14201419
// Deploy StakingReverter contract
1421-
stkReverterAddr, err = s.factory.DeployContract(
1420+
stkReverterAddr, err := s.factory.DeployContract(
14221421
delegator.Priv,
14231422
evmtypes.EvmTxArgs{}, // NOTE: passing empty struct to use default values
14241423
testutiltypes.ContractDeploymentData{
@@ -1430,7 +1429,7 @@ func TestPrecompileIntegrationTestSuite(t *testing.T, create network.CreateEvmAp
14301429

14311430
// send some funds to the StakingCallerTwo & StakingReverter contracts to transfer to the
14321431
// delegator during the tx
1433-
err := utils.FundAccountWithBaseDenom(s.factory, s.network, s.keyring.GetKey(0), contractTwoAddr.Bytes(), testContractInitialBalance)
1432+
err = utils.FundAccountWithBaseDenom(s.factory, s.network, s.keyring.GetKey(0), contractTwoAddr.Bytes(), testContractInitialBalance)
14341433
Expect(err).To(BeNil(), "error while funding the smart contract: %v", err)
14351434
Expect(s.network.NextBlock()).To(BeNil())
14361435
err = utils.FundAccountWithBaseDenom(s.factory, s.network, s.keyring.GetKey(0), stkReverterAddr.Bytes(), testContractInitialBalance)

tests/integration/precompiles/werc20/test_events.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"math/big"
55

66
"github.com/ethereum/go-ethereum/common"
7-
"github.com/ethereum/go-ethereum/crypto"
87
"github.com/stretchr/testify/suite"
98

109
cmn "github.com/cosmos/evm/precompiles/common"
@@ -129,9 +128,8 @@ func (s *PrecompileUnitTestSuite) TestEmitDepositEvent() {
129128
s.Require().Equal(log.Address, s.precompile.Address())
130129

131130
// Check on the topics
132-
event := s.precompile.Events[werc20.EventTypeDeposit]
133131
s.Require().Equal(
134-
crypto.Keccak256Hash([]byte(event.Sig)),
132+
(&werc20.DepositEvent{}).GetEventID(),
135133
common.HexToHash(log.Topics[0].Hex()),
136134
)
137135
var adddressTopic common.Hash
@@ -141,8 +139,8 @@ func (s *PrecompileUnitTestSuite) TestEmitDepositEvent() {
141139
s.Require().EqualValues(log.BlockNumber, s.network.GetContext().BlockHeight())
142140

143141
// Verify data
144-
var depositEvent DepositEvent
145-
err = cmn.UnpackLog(s.precompile.ABI, &depositEvent, werc20.EventTypeDeposit, *log)
142+
var depositEvent werc20.DepositEvent
143+
err = cmn.UnpackLog(&depositEvent, *log)
146144
s.Require().NoError(err, "unable to unpack log into deposit event")
147145

148146
s.Require().Equal(caller, depositEvent.Dst, "expected different destination address")
@@ -188,9 +186,8 @@ func (s *PrecompileUnitTestSuite) TestEmitWithdrawalEvent() {
188186
s.Require().Equal(log.Address, s.precompile.Address())
189187

190188
// Check on the topics
191-
event := s.precompile.Events[werc20.EventTypeWithdrawal]
192189
s.Require().Equal(
193-
crypto.Keccak256Hash([]byte(event.Sig)),
190+
(&werc20.WithdrawalEvent{}).GetEventID(),
194191
common.HexToHash(log.Topics[0].Hex()),
195192
)
196193
var adddressTopic common.Hash
@@ -200,8 +197,8 @@ func (s *PrecompileUnitTestSuite) TestEmitWithdrawalEvent() {
200197
s.Require().EqualValues(log.BlockNumber, s.network.GetContext().BlockHeight())
201198

202199
// Verify data
203-
var withdrawalEvent WithdrawalEvent
204-
err = cmn.UnpackLog(s.precompile.ABI, &withdrawalEvent, werc20.EventTypeWithdrawal, *log)
200+
var withdrawalEvent werc20.WithdrawalEvent
201+
err = cmn.UnpackLog(&withdrawalEvent, *log)
205202
s.Require().NoError(err, "unable to unpack log into withdrawal event")
206203

207204
s.Require().Equal(caller, withdrawalEvent.Src, "expected different source address")

0 commit comments

Comments
 (0)