diff --git a/cosmos/testing/e2e/polariserc20/polaris_test.go b/cosmos/testing/e2e/polariserc20/polaris_test.go index ff7b8f811..89c29af53 100644 --- a/cosmos/testing/e2e/polariserc20/polaris_test.go +++ b/cosmos/testing/e2e/polariserc20/polaris_test.go @@ -125,5 +125,31 @@ var _ = Describe("ERC20", func() { Expect(res.Cmp(big.NewInt(50))).To(Equal(0)) }) + It("should still include reverted transactions in a block", func() { + // originate a ERC20 token + contract, _ := DeployERC20(tf.GenerateTransactOpts("alice"), tf.EthClient()) + + // mint some tokens to bob + tx, err := contract.Mint( + tf.GenerateTransactOpts("bob"), tf.Address("bob"), big.NewInt(123456789), + ) + Expect(err).ToNot(HaveOccurred()) + ExpectSuccessReceipt(tf.EthClient(), tx) + + // check that the new ERC20 is minted to bob + bal, err := contract.BalanceOf(nil, tf.Address("bob")) + Expect(err).ToNot(HaveOccurred()) + Expect(bal).To(Equal(big.NewInt(123456789))) + + // ensure alice cannot transferFrom bob's account + tx, err = contract.TransferFrom( + tf.GenerateTransactOpts("alice"), + tf.Address("bob"), + tf.Address("alice"), + big.NewInt(6789), + ) + Expect(err).ToNot(HaveOccurred()) + ExpectFailedReceipt(tf.EthClient(), tx) + }) }) }) diff --git a/cosmos/x/evm/keeper/processor_test.go b/cosmos/x/evm/keeper/processor_test.go index 1bb6a4fe6..e10f43e2e 100644 --- a/cosmos/x/evm/keeper/processor_test.go +++ b/cosmos/x/evm/keeper/processor_test.go @@ -131,8 +131,9 @@ var _ = Describe("Processor", func() { Context("New Block", func() { BeforeEach(func() { - // before every tx - ctx = ctx.WithGasMeter(storetypes.NewInfiniteGasMeter()) + // before every tx, every tx has gas limit of 100000000 + ctx = ctx.WithGasMeter(storetypes.NewGasMeter(100000000)) + k.GetHost().GetGasPlugin().Reset(ctx) }) AfterEach(func() { @@ -154,8 +155,10 @@ var _ = Describe("Processor", func() { }) It("should successfully deploy a valid contract and call it", func() { + // create the contract legacyTxData.Data = common.FromHex(bindings.SolmateERC20Bin) legacyTxData.GasPrice = big.NewInt(10000000000) + legacyTxData.Gas = k.GetHost().GetGasPlugin().TxGasRemaining() tx := coretypes.MustSignNewTx(key, signer, legacyTxData) addr, err := signer.Sender(tx) Expect(err).ToNot(HaveOccurred()) @@ -163,12 +166,13 @@ var _ = Describe("Processor", func() { k.GetHost().GetStatePlugin().CreateAccount(addr) k.GetHost().GetStatePlugin().AddBalance(addr, (&big.Int{}).Mul(big.NewInt(9000000000000000000), big.NewInt(999))) k.GetHost().GetStatePlugin().Finalize() - - // create the contract result, err := k.ProcessTransaction(ctx, tx) Expect(err).ToNot(HaveOccurred()) Expect(result.Err).ToNot(HaveOccurred()) + // call the contract non-view function + ctx = ctx.WithGasMeter(storetypes.NewGasMeter(100000000)) + k.GetHost().GetGasPlugin().Reset(ctx) deployAddress := crypto.CreateAddress(crypto.PubkeyToAddress(key.PublicKey), 0) legacyTxData.To = &deployAddress var solmateABI abi.ABI @@ -177,6 +181,7 @@ var _ = Describe("Processor", func() { input, err := solmateABI.Pack("mint", common.BytesToAddress([]byte{0x88}), big.NewInt(8888888)) Expect(err).ToNot(HaveOccurred()) legacyTxData.Data = input + legacyTxData.Gas = k.GetHost().GetGasPlugin().TxGasRemaining() legacyTxData.Nonce++ tx = coretypes.MustSignNewTx(key, signer, legacyTxData) result, err = k.ProcessTransaction(ctx, tx) @@ -184,7 +189,10 @@ var _ = Describe("Processor", func() { Expect(result.Err).ToNot(HaveOccurred()) // call the contract view function + ctx = ctx.WithGasMeter(storetypes.NewGasMeter(100000000)) + k.GetHost().GetGasPlugin().Reset(ctx) legacyTxData.Data = crypto.Keccak256Hash([]byte("totalSupply()")).Bytes()[:4] + legacyTxData.Gas = k.GetHost().GetGasPlugin().TxGasRemaining() legacyTxData.Nonce++ tx = coretypes.MustSignNewTx(key, signer, legacyTxData) result, err = k.ProcessTransaction(ctx, tx) diff --git a/lib/utils/math.go b/lib/utils/math.go index 06eb8aab4..4ecef6866 100644 --- a/lib/utils/math.go +++ b/lib/utils/math.go @@ -25,18 +25,18 @@ package utils -import ( - "golang.org/x/exp/constraints" -) +type Numerical interface { + ~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 +} -func Min[T constraints.Ordered](a, b T) T { +func Min[T Numerical](a, b T) T { if a < b { return a } return b } -func Max[T constraints.Ordered](a, b T) T { +func Max[T Numerical](a, b T) T { if a > b { return a }