-
Notifications
You must be signed in to change notification settings - Fork 530
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add eth_call override * Pass lint * Apply feedback --------- Co-authored-by: Victor Castell <victor@victorcastell.com>
- Loading branch information
Showing
16 changed files
with
287 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
consensus/polybft/contractsapi/test-contracts/TestSimple.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"_format": "hh-sol-artifact-1", | ||
"contractName": "TestSimple", | ||
"sourceName": "contracts/TestSimple.sol", | ||
"abi": [ | ||
{ | ||
"inputs": [], | ||
"name": "getValue", | ||
"outputs": [ | ||
{ | ||
"internalType": "uint256", | ||
"name": "", | ||
"type": "uint256" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
} | ||
], | ||
"bytecode": "0x608060405234801561001057600080fd5b5060b68061001f6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c80632096525514602d575b600080fd5b60336047565b604051603e91906067565b60405180910390f35b60008054905090565b6000819050919050565b6061816050565b82525050565b6000602082019050607a6000830184605a565b9291505056fea26469706673582212203adde2f97bef70ed52dd170d2965805f1ed0cd3eaa229edc27180041091175ac64736f6c63430008110033", | ||
"deployedBytecode": "0x6080604052348015600f57600080fd5b506004361060285760003560e01c80632096525514602d575b600080fd5b60336047565b604051603e91906067565b60405180910390f35b60008054905090565b6000819050919050565b6061816050565b82525050565b6000602082019050607a6000830184605a565b9291505056fea26469706673582212203adde2f97bef70ed52dd170d2965805f1ed0cd3eaa229edc27180041091175ac64736f6c63430008110033", | ||
"linkReferences": {}, | ||
"deployedLinkReferences": {} | ||
} |
10 changes: 10 additions & 0 deletions
10
consensus/polybft/contractsapi/test-contracts/TestSimple.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.17; | ||
|
||
contract TestSimple { | ||
uint256 val; | ||
|
||
function getValue() public view returns (uint256) { | ||
return val; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package e2e | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/0xPolygon/polygon-edge/consensus/polybft/contractsapi" | ||
"github.com/0xPolygon/polygon-edge/e2e-polybft/framework" | ||
"github.com/0xPolygon/polygon-edge/types" | ||
"github.com/stretchr/testify/require" | ||
"github.com/umbracle/ethgo" | ||
"github.com/umbracle/ethgo/abi" | ||
"github.com/umbracle/ethgo/wallet" | ||
) | ||
|
||
func TestE2E_JsonRPC(t *testing.T) { | ||
acct, _ := wallet.GenerateKey() | ||
|
||
cluster := framework.NewTestCluster(t, 3, | ||
framework.WithPremine(types.Address(acct.Address())), | ||
) | ||
defer cluster.Stop() | ||
|
||
cluster.WaitForReady(t) | ||
|
||
client := cluster.Servers[0].JSONRPC().Eth() | ||
|
||
// Test eth_call with override in state diff | ||
t.Run("eth_call state override", func(t *testing.T) { | ||
deployTxn := cluster.Deploy(t, acct, contractsapi.TestSimple.Bytecode) | ||
require.NoError(t, deployTxn.Wait()) | ||
require.True(t, deployTxn.Succeed()) | ||
|
||
target := deployTxn.Receipt().ContractAddress | ||
|
||
input := abi.MustNewMethod("function getValue() public returns (uint256)").ID() | ||
|
||
resp, err := client.Call(ðgo.CallMsg{To: &target, Data: input}, ethgo.Latest) | ||
require.NoError(t, err) | ||
require.Equal(t, "0x0000000000000000000000000000000000000000000000000000000000000000", resp) | ||
|
||
override := ðgo.StateOverride{ | ||
target: ethgo.OverrideAccount{ | ||
StateDiff: &map[ethgo.Hash]ethgo.Hash{ | ||
// storage slot 0 stores the 'val' uint256 value | ||
{0x0}: {0x3}, | ||
}, | ||
}, | ||
} | ||
|
||
resp, err = client.Call(ðgo.CallMsg{To: &target, Data: input}, ethgo.Latest, override) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, "0x0300000000000000000000000000000000000000000000000000000000000000", resp) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package state | ||
|
||
import ( | ||
"math/big" | ||
"testing" | ||
|
||
"github.com/0xPolygon/polygon-edge/chain" | ||
"github.com/0xPolygon/polygon-edge/types" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestOverride(t *testing.T) { | ||
t.Parallel() | ||
state := newStateWithPreState(map[types.Address]*PreState{ | ||
{0x0}: { | ||
Nonce: 1, | ||
Balance: 1, | ||
State: map[types.Hash]types.Hash{ | ||
types.ZeroHash: {0x1}, | ||
}, | ||
}, | ||
{0x1}: { | ||
State: map[types.Hash]types.Hash{ | ||
types.ZeroHash: {0x1}, | ||
}, | ||
}, | ||
}) | ||
|
||
nonce := uint64(2) | ||
balance := big.NewInt(2) | ||
code := []byte{0x1} | ||
|
||
tt := NewTransition(chain.ForksInTime{}, state, newTxn(state)) | ||
|
||
require.Empty(t, tt.state.GetCode(types.ZeroAddress)) | ||
|
||
err := tt.WithStateOverride(types.StateOverride{ | ||
{0x0}: types.OverrideAccount{ | ||
Nonce: &nonce, | ||
Balance: balance, | ||
Code: code, | ||
StateDiff: map[types.Hash]types.Hash{ | ||
types.ZeroHash: {0x2}, | ||
}, | ||
}, | ||
{0x1}: types.OverrideAccount{ | ||
State: map[types.Hash]types.Hash{ | ||
{0x1}: {0x1}, | ||
}, | ||
}, | ||
}) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, nonce, tt.state.GetNonce(types.ZeroAddress)) | ||
require.Equal(t, balance, tt.state.GetBalance(types.ZeroAddress)) | ||
require.Equal(t, code, tt.state.GetCode(types.ZeroAddress)) | ||
require.Equal(t, types.Hash{0x2}, tt.state.GetState(types.ZeroAddress, types.ZeroHash)) | ||
|
||
// state is fully replaced | ||
require.Equal(t, types.Hash{0x0}, tt.state.GetState(types.Address{0x1}, types.ZeroHash)) | ||
require.Equal(t, types.Hash{0x1}, tt.state.GetState(types.Address{0x1}, types.Hash{0x1})) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.