-
Notifications
You must be signed in to change notification settings - Fork 118
feat(x/vm): apply stack-based StateDB snapshot mechamism for precompile call #244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 18 commits
ddd79b5
7516b28
293bc02
f14eea0
30040a7
a6628ef
490a0b6
3fcb7db
fdc0c16
229367d
6ececba
ae18153
f7b26bb
d2f40c7
2972d22
6af41b0
ee190f6
c6cb162
70cddf2
0f00851
df311f3
c4f0266
3ad3763
4a9b5aa
264a8fe
a881f29
ae1c9fc
33f939a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -497,13 +497,18 @@ func (s *PrecompileTestSuite) TestCMS() { | |
| if tc.expPass { | ||
| s.Require().NoError(err, "expected no error when running the precompile") | ||
| s.Require().NotNil(resp.Ret, "expected returned bytes not to be nil") | ||
| testutil.ValidateWrites(s.T(), cms, 2) | ||
| // NOTES: After stack-based snapshot mechanism is added for precopile call, | ||
| // CacheMultiStore.Write() is always called once when tx succeeds. | ||
| // It is because CacheMultiStore() is not called when creating snapshot for MultiStore, | ||
| // Count of Write() is not accumulated. | ||
| testutil.ValidateWrites(s.T(), cms, 1) | ||
| } else { | ||
| s.Require().Error(err, "expected error to be returned when running the precompile") | ||
| s.Require().Nil(resp.Ret, "expected returned bytes to be nil") | ||
| s.Require().ErrorContains(err, tc.errContains) | ||
| // Writes once because of gas usage | ||
| testutil.ValidateWrites(s.T(), cms, 1) | ||
| // NOTES: After stack-based snapshot mechanism is added for precopile call, | ||
|
||
| // CacheMultiStore.Write() is not called when tx fails. | ||
| testutil.ValidateWrites(s.T(), cms, 0) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1834,6 +1834,54 @@ func TestPrecompileIntegrationTestSuite(t *testing.T, create network.CreateEvmAp | |
| Expect(err).NotTo(BeNil()) | ||
| Expect(err.Error()).To(ContainSubstring("not found"), "expected NO delegation created") | ||
| }) | ||
|
|
||
| It("should delegate before and after intentionaly ignored delegation revert - successful tx", func() { | ||
| delegationAmount := math.NewInt(10) | ||
| expectedDelegationAmount := delegationAmount.Add(delegationAmount) | ||
|
|
||
| callArgs := testutiltypes.CallArgs{ | ||
| ContractABI: stakingReverterContract.ABI, | ||
| MethodName: "callPrecompileBeforeAndAfterRevert", | ||
| Args: []interface{}{ | ||
| big.NewInt(5), s.network.GetValidators()[0].OperatorAddress, | ||
| }, | ||
| } | ||
|
|
||
| delegateCheck := passCheck.WithExpEvents(staking.EventTypeDelegate, staking.EventTypeDelegate) | ||
| // Tx should be successful, but no state changes happened | ||
|
||
| res, _, err := s.factory.CallContractAndCheckLogs( | ||
| s.keyring.GetPrivKey(0), | ||
| evmtypes.EvmTxArgs{ | ||
| To: &stkReverterAddr, | ||
| GasPrice: gasPrice.BigInt(), | ||
| }, | ||
| callArgs, | ||
| delegateCheck, | ||
| ) | ||
| Expect(err).To(BeNil(), "error while calling the smart contract: %v", err) | ||
| Expect(s.network.NextBlock()).To(BeNil()) | ||
|
|
||
| fees := gasPrice.MulRaw(res.GasUsed) | ||
|
|
||
| // delegation should have been created | ||
| qRes, err := s.grpcHandler.GetDelegation(sdk.AccAddress(stkReverterAddr.Bytes()).String(), s.network.GetValidators()[0].OperatorAddress) | ||
| Expect(err).To(BeNil()) | ||
| Expect(qRes.DelegationResponse.Delegation.GetDelegatorAddr()).To(Equal(sdk.AccAddress(stkReverterAddr.Bytes()).String()), "expected delegator address is equal to contract address") | ||
| Expect(qRes.DelegationResponse.Delegation.GetShares().BigInt()).To(Equal(expectedDelegationAmount.BigInt()), "expected different delegation shares") | ||
|
|
||
| // contract balance should be deducted by delegation amount | ||
| balRes, err := s.grpcHandler.GetBalanceFromBank(stkReverterAddr.Bytes(), s.bondDenom) | ||
| Expect(err).To(BeNil()) | ||
| contractFinalBalance := balRes.Balance | ||
| Expect(contractFinalBalance.Amount).To(Equal(contractInitialBalance.Amount.Sub(expectedDelegationAmount))) | ||
|
|
||
| // fees deducted on tx sender. | ||
| // delegation amount is deducted on contract balance that is previously funded. | ||
| balRes, err = s.grpcHandler.GetBalanceFromBank(s.keyring.GetAccAddr(0), s.bondDenom) | ||
| Expect(err).To(BeNil()) | ||
| txSenderFinalBal := balRes.Balance | ||
| Expect(txSenderFinalBal.Amount).To(Equal(txSenderInitialBal.Amount.Sub(fees)), "expected tx sender balance to be deducted by fees") | ||
| }) | ||
| }) | ||
|
|
||
| Context("Table-driven tests for Delegate method", func() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo in precopile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in 264a8fe