Skip to content

Commit 87bf029

Browse files
committed
Add special signatures handling integration tests
1 parent 9427d4b commit 87bf029

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

tests/nodeos_eos_evm_test.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,73 @@ def makeReservedEvmAddress(account):
675675
if testAccActualAmount != expectedAmount:
676676
Utils.errorExit("Transfer verification failed. Excepted %s, actual: %s" % (expectedAmount, testAccActualAmount))
677677

678+
### Special signature test (begin)
679+
# Increment contract
680+
'''
681+
// SPDX-License-Identifier: GPL-3.0
682+
pragma solidity >=0.8.2 <0.9.0;
683+
contract Increment {
684+
mapping (address => uint256) values;
685+
function increment() public {
686+
values[msg.sender]++;
687+
}
688+
function retrieve(address a) public view returns (uint256){
689+
return values[a];
690+
}
691+
}
692+
'''
693+
694+
accSpecialKey = '344260572d5df010d70597386bfeeaecf863a8dbbe3c9a023f81d7056b28815f'
695+
accSpecialAdd = w3.eth.account.from_key(accSpecialKey).address
696+
697+
prodNode.transferFunds(testAcc, evmAcc, "10.0000 EOS", "0x0290ffefa58ee84a3641770ab910c48d3441752d", waitForTransBlock=True)
698+
prodNode.transferFunds(testAcc, evmAcc, "1000.0000 EOS", accSpecialAdd, waitForTransBlock=True)
699+
700+
# Test special signature handling (contract and evm-node)
701+
Print("Test special signature handling (both contract and evm-node)")
702+
special_nonce = 0
703+
signed_trx = w3.eth.account.sign_transaction(dict(
704+
nonce=special_nonce,
705+
gas=1000000,
706+
gasPrice=getGasPrice(),
707+
data=Web3.to_bytes(hexstr='608060405234801561001057600080fd5b50610284806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80630a79309b1461003b578063d09de08a1461006b575b600080fd5b61005560048036038101906100509190610176565b610075565b60405161006291906101bc565b60405180910390f35b6100736100bd565b005b60008060008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050919050565b6000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600081548092919061010c90610206565b9190505550565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b600061014382610118565b9050919050565b61015381610138565b811461015e57600080fd5b50565b6000813590506101708161014a565b92915050565b60006020828403121561018c5761018b610113565b5b600061019a84828501610161565b91505092915050565b6000819050919050565b6101b6816101a3565b82525050565b60006020820190506101d160008301846101ad565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000610211826101a3565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203610243576102426101d7565b5b60018201905091905056fea264697066735822122026d27f46966ee75c7a8b2a43923c8796438013de730eb9eec6c24ff581913d6864736f6c63430008120033'),
708+
chainId=15555
709+
), accSpecialKey)
710+
711+
# Deploy "Increment" contract
712+
increment_contract = makeContractAddress(accSpecialAdd, special_nonce)
713+
actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(signed_trx.rawTransaction)[2:]}
714+
trans = prodNode.pushMessage(evmAcc.name, "pushtx", json.dumps(actData), '-p {0}'.format(minerAcc.name), silentErrors=True)
715+
prodNode.waitForTransBlockIfNeeded(trans[1], True);
716+
717+
# Test special signature: Call from `accSpecialAdd`
718+
special_nonce += 1
719+
signed_trx = w3.eth.account.sign_transaction(dict(
720+
nonce=special_nonce,
721+
gas=1000000,
722+
gasPrice=getGasPrice(),
723+
to=Web3.to_checksum_address(increment_contract),
724+
data=Web3.to_bytes(hexstr='D09DE08A'), # sha3(increment())=0xD09DE08A
725+
chainId=15555
726+
), accSpecialKey)
727+
728+
actData = {"miner":minerAcc.name, "rlptx":Web3.to_hex(signed_trx.rawTransaction)[2:]}
729+
trans = prodNode.pushMessage(evmAcc.name, "pushtx", json.dumps(actData), '-p {0}'.format(minerAcc.name), silentErrors=True)
730+
prodNode.waitForTransBlockIfNeeded(trans[1], True);
731+
732+
# Test special signature: Call from miner account
733+
actData = {"from":minerAcc.name, "to":increment_contract[2:], "value":"0000000000000000000000000000000000000000000000000000000000000000", "data":"d09de08a", "gas_limit":"100000"}
734+
trans = prodNode.pushMessage(evmAcc.name, "call", json.dumps(actData), '-p {0}'.format(minerAcc.name), silentErrors=True)
735+
prodNode.waitForTransBlockIfNeeded(trans[1], True);
736+
737+
# Test special signature: Call from `0x0290ffefa58ee84a3641770ab910c48d3441752d`
738+
prodNode.transferFunds(testAcc, evmAcc, "10.0000 EOS", "0x0290ffefa58ee84a3641770ab910c48d3441752d", waitForTransBlock=True)
739+
actData = {"from":"0290ffefa58ee84a3641770ab910c48d3441752d", "to":increment_contract[2:], "value":"0000000000000000000000000000000000000000000000000000000000000000", "data":"d09de08a", "gas_limit":"100000"}
740+
trans = prodNode.pushMessage(evmAcc.name, "admincall", json.dumps(actData), '-p {0}'.format(evmAcc.name), silentErrors=True)
741+
prodNode.waitForTransBlockIfNeeded(trans[1], True);
742+
743+
### Special signature test (end)
744+
678745
# test hard-failed transaction (with --delay-sec)
679746
amount=7.0000
680747
transferAmount="7.000 {0}".format(CORE_SYMBOL)
@@ -847,6 +914,15 @@ def makeReservedEvmAddress(account):
847914
raise
848915
assert r == int(row['balance'],16), f"{row['eth_address']} {r} != {int(row['balance'],16)}"
849916

917+
# Validate special signatures handling
918+
def get_stored_value(address):
919+
result = processUrllibRequest("http://127.0.0.1:8881", payload={"method":"eth_call","params":[{"from":fromAdd, "to":increment_contract, "data":"0x0a79309b000000000000000000000000"+address}, "latest"],"id":1,"jsonrpc":"2.0"})
920+
return int(result["payload"]["result"], 16)
921+
922+
assert(get_stored_value(accSpecialAdd[2:]) == 1) #pushtx
923+
assert(get_stored_value(makeReservedEvmAddress(convert_name_to_value(minerAcc.name))[2:]) == 1) #call
924+
assert(get_stored_value('0290ffefa58ee84a3641770ab910c48d3441752d') == 1) #admincall
925+
850926
foundErr = False
851927
stdErrFile = open(nodeStdErrDir, "r")
852928
lines = stdErrFile.readlines()

0 commit comments

Comments
 (0)