Skip to content

Commit

Permalink
fix integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Oct 27, 2023
1 parent dff8931 commit 769cddf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
5 changes: 5 additions & 0 deletions tests/integration_tests/hardhat/contracts/Greeter.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pragma solidity >0.5.0;

contract Greeter {
uint public n;
string public greeting;

event ChangeGreeting(address from, string value);
Expand All @@ -17,4 +18,8 @@ contract Greeter {
function greet() public view returns (string memory) {
return greeting;
}

function intValue() public view returns (uint) {
return n;
}
}
33 changes: 25 additions & 8 deletions tests/integration_tests/test_call.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
from web3 import Web3
import json
from web3 import Web3
from web3._utils.contracts import encode_transaction_data
from hexbytes import HexBytes

from .utils import CONTRACTS


def test_state_override(ethermint):
w3: Web3 = ethermint.w3
info = json.loads(CONTRACTS['Greeter'].read_text())
address = "0x0000000000000000000000000000ffffffffffff"
def test_state_override(cronos):
state = 100
w3: Web3 = cronos.w3
info = json.loads(CONTRACTS["Greeter"].read_text())
data = encode_transaction_data(w3, "intValue", info["abi"])
# call an arbitrary address
address = w3.toChecksumAddress("0x0000000000000000000000000000ffffffffffff")
overrides = {
address: {
"code": info['deployedBytecode'],
"code": info["deployedBytecode"],
"state": {
("0x" + "0" * 64): HexBytes(
w3.codec.encode(("uint256",), (state,))
).hex(),
},
},
}
contract = w3.eth.contract(abi=info['abi'], address=address)
print(contract.greet().call("latest", overrides))
result = w3.eth.call(
{
"to": address,
"data": data,
},
"latest",
overrides,
)
assert (state,) == w3.codec.decode(("uint256",), result)

0 comments on commit 769cddf

Please sign in to comment.