Skip to content

Commit

Permalink
Merge pull request #1013 from qtumproject/neil/shanghai-tests
Browse files Browse the repository at this point in the history
Neil/shanghai tests
  • Loading branch information
qtum-neil authored Aug 28, 2023
2 parents 3c0bc05 + aaf8ea6 commit 79d2f5b
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 47 deletions.
2 changes: 1 addition & 1 deletion test/functional/feature_dbcrash.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def run_test(self):
while current_height + 1 > self.nodes[3].getblockcount():
block_hashes.extend(self.generatetoaddress(
self.nodes[3],
nblocks=min(10, current_height + 1 - self.nodes[3].getblockcount()),
nblocks=10,
# new address to avoid mining a block that has just been invalidated
address=getnewdestination()[2],
sync_fun=self.no_op,
Expand Down
22 changes: 17 additions & 5 deletions test/functional/qtum_evm_create2.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,27 @@ def assert_state(self, node, gas, gas_price, gas_used, value, excepted):
txids = block['tx']
coinbase_tx = node.getrawtransaction(txids[0], True, blockhash)
call_tx = node.getrawtransaction(txids[1], True, blockhash)

input_tx = node.decoderawtransaction(node.gettransaction(call_tx['vin'][0]['txid'])['hex'])
sender_utxo = input_tx['vout'][call_tx['vin'][0]['vout']]
sender_address = sender_utxo['scriptPubKey']['address']

for op_call_vout_index in range(len(call_tx['vout'])):
if call_tx['vout'][op_call_vout_index]['scriptPubKey']['type'] == 'call_sender':
if call_tx['vout'][op_call_vout_index]['scriptPubKey']['type'] in ['call', 'call_sender']:

sender_utxo = input_tx['vout'][call_tx['vin'][0]['vout']]
sender_address = sender_utxo['scriptPubKey']['address']
vin0_output = 'OP_DUP OP_HASH160 ' + p2pkh_to_hex_hash(sender_address) + ' OP_EQUALVERIFY OP_CHECKSIG'

if call_tx['vout'][op_call_vout_index]['scriptPubKey']['type'] == 'call_sender':
sender_utxo = {
'scriptPubKey': {
'asm': ''
}
}
sender_hex = call_tx['vout'][op_call_vout_index]['scriptPubKey']['asm'].split(" ")[1]
sender_address = hex_hash_to_p2pkh(sender_hex)
sender_utxo['scriptPubKey']['asm'] = 'OP_DUP OP_HASH160 ' + sender_hex + ' OP_EQUALVERIFY OP_CHECKSIG'

break

# Check that the transaction receipt is correct
receipt = node.gettransactionreceipt(call_tx['txid'])[0]
assert_equal(receipt['gasUsed'], gas_used)
Expand Down
85 changes: 44 additions & 41 deletions test/functional/qtum_evm_globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,23 @@ def verify_evm_globals_test(self, use_staking=False):
self.node.sendtoaddress(sender, 1)
self.node.generate(1)
"""
9950fc69 blockblockhash(uint256)
18b66ea3 blockcoinbase()
5df32c47 blockdifficulty()
805f6831 blockgaslimit()
05062247 blocknumber()
8182a11f blocktimestamp()
e9ac31f2 msgdata()
522a3926 msggas()
61c99b92 msgsender()
96acd236 msgsig()
f8184f73 msgvalue()
cc5ea9ad setGlobals()
d76c09ad txgasprice()
2c7622b0 txorigin()
Function signatures:
9950fc69: blockblockhash(uint256)
18b66ea3: blockcoinbase()
5df32c47: blockdifficulty()
805f6831: blockgaslimit()
05062247: blocknumber()
8182a11f: blocktimestamp()
cd84980e: chainid()
e9ac31f2: msgdata()
522a3926: msggas()
61c99b92: msgsender()
96acd236: msgsig()
f8184f73: msgvalue()
cc5ea9ad: setGlobals()
d76c09ad: txgasprice()
2c7622b0: txorigin()
"""
self.node.sendtocontract(self.contract_address, "cc5ea9ad", 1, 20000000, QTUM_MIN_GAS_PRICE/COIN, sender)

Expand Down Expand Up @@ -117,6 +120,10 @@ def verify_evm_globals_test(self, use_staking=False):
# block.timestamp
print(' block.timestamp')
assert_equal(block['time'], int(self.get_contract_call_output("8182a11f"), 16))

# block.chainid
print(' block.chainid')
assert_equal(8890, int(self.get_contract_call_output("cd84980e"), 16))

# msg.gas
print(' msg.gas')
Expand All @@ -143,17 +150,15 @@ def verify_evm_globals_test(self, use_staking=False):
assert_equal(sender_pkh, self.get_contract_call_output("2c7622b0")[24:])
self.sync_all()


def run_test(self):
self.node = self.nodes[0]
self.connect_nodes(0, 1)
address = self.node.getnewaddress()
generatesynchronized(self.node, 10 + COINBASE_MATURITY, address, self.nodes)

"""
pragma solidity ^0.4.12;
pragma solidity >=0.8.0;
contract TestEVM {
address public blockcoinbase;
mapping(uint => bytes32) public blockblockhash;
Expand All @@ -168,46 +173,48 @@ def run_test(self):
uint public msgvalue;
uint public txgasprice;
address public txorigin;
function setGlobals() payable {
uint public chainid;
function setGlobals() public payable {
for(uint i = 0; i <= 257; ++i) {
blockblockhash[block.number - i] = block.blockhash(block.number - i);
blockblockhash[block.number - i] = blockhash(block.number - i);
}
blockcoinbase = block.coinbase;
blockdifficulty = block.difficulty;
blockdifficulty = block.prevrandao;
blockgaslimit = block.gaslimit;
blocknumber = block.number;
blocktimestamp = block.timestamp;
chainid = block.chainid;
msgdata = msg.data;
msggas = msg.gas;
msggas = gasleft();
msgsender = msg.sender;
msgsig = msg.sig;
msgvalue = msg.value;
txgasprice = tx.gasprice;
txorigin = tx.origin;
}
}
"""
bytecode = "6060604052341561000f57600080fd5b5b6108298061001f6000396000f300606060405236156100ce576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806305062247146100d357806318b66ea3146100fc5780632c7622b014610151578063522a3926146101a65780635df32c47146101cf57806361c99b92146101f8578063805f68311461024d5780638182a11f1461027657806396acd2361461029f5780639950fc6914610306578063cc5ea9ad14610345578063d76c09ad1461034f578063e9ac31f214610378578063f8184f7314610407575b600080fd5b34156100de57600080fd5b6100e6610430565b6040518082815260200191505060405180910390f35b341561010757600080fd5b61010f610436565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b341561015c57600080fd5b61016461045b565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34156101b157600080fd5b6101b9610481565b6040518082815260200191505060405180910390f35b34156101da57600080fd5b6101e2610487565b6040518082815260200191505060405180910390f35b341561020357600080fd5b61020b61048d565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b341561025857600080fd5b6102606104b3565b6040518082815260200191505060405180910390f35b341561028157600080fd5b6102896104b9565b6040518082815260200191505060405180910390f35b34156102aa57600080fd5b6102b26104bf565b60405180827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19167bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916815260200191505060405180910390f35b341561031157600080fd5b61032760048080359060200190919050506104ee565b60405180826000191660001916815260200191505060405180910390f35b61034d610506565b005b341561035a57600080fd5b6103626106ae565b6040518082815260200191505060405180910390f35b341561038357600080fd5b61038b6106b4565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156103cc5780820151818401525b6020810190506103b0565b50505050905090810190601f1680156103f95780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561041257600080fd5b61041a610752565b6040518082815260200191505060405180910390f35b60045481565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600b60009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60075481565b60025481565b600860009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60035481565b60055481565b600860149054906101000a90047c01000000000000000000000000000000000000000000000000000000000281565b60016020528060005260406000206000915090505481565b6000600190505b61010081111515610545578043034060016000834303815260200190815260200160002081600019169055505b80600101905061050d565b416000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555044600281905550456003819055504360048190555042600581905550600036600691906105b3929190610758565b505a60078190555033600860006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506000357fffffffff0000000000000000000000000000000000000000000000000000000016600860146101000a81548163ffffffff02191690837c010000000000000000000000000000000000000000000000000000000090040217905550346009819055503a600a8190555032600b60006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505b50565b600a5481565b60068054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561074a5780601f1061071f5761010080835404028352916020019161074a565b820191906000526020600020905b81548152906001019060200180831161072d57829003601f168201915b505050505081565b60095481565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061079957803560ff19168380011785556107c7565b828001600101855582156107c7579182015b828111156107c65782358255916020019190600101906107ab565b5b5090506107d491906107d8565b5090565b6107fa91905b808211156107f65760008160009055506001016107de565b5090565b905600a165627a7a7230582035fd01aecdb713f1bf582f346a4ffe69efe883d4c8744bbd5262505e0d13dfb20029"
bytecode = "608060405234801561000f575f80fd5b50610c258061001d5f395ff3fe6080604052600436106100e7575f3560e01c80638182a11f11610089578063cd84980e11610058578063cd84980e146102ab578063d76c09ad146102d5578063e9ac31f2146102ff578063f8184f7314610329576100e7565b80638182a11f1461021157806396acd2361461023b5780639950fc6914610265578063cc5ea9ad146102a1576100e7565b8063522a3926116100c5578063522a3926146101695780635df32c471461019357806361c99b92146101bd578063805f6831146101e7576100e7565b806305062247146100eb57806318b66ea3146101155780632c7622b01461013f575b5f80fd5b3480156100f6575f80fd5b506100ff610353565b60405161010c9190610652565b60405180910390f35b348015610120575f80fd5b50610129610359565b60405161013691906106aa565b60405180910390f35b34801561014a575f80fd5b5061015361037c565b60405161016091906106aa565b60405180910390f35b348015610174575f80fd5b5061017d6103a1565b60405161018a9190610652565b60405180910390f35b34801561019e575f80fd5b506101a76103a7565b6040516101b49190610652565b60405180910390f35b3480156101c8575f80fd5b506101d16103ad565b6040516101de91906106aa565b60405180910390f35b3480156101f2575f80fd5b506101fb6103d2565b6040516102089190610652565b60405180910390f35b34801561021c575f80fd5b506102256103d8565b6040516102329190610652565b60405180910390f35b348015610246575f80fd5b5061024f6103de565b60405161025c91906106fd565b60405180910390f35b348015610270575f80fd5b5061028b60048036038101906102869190610744565b6103f1565b6040516102989190610787565b60405180910390f35b6102a9610406565b005b3480156102b6575f80fd5b506102bf61059c565b6040516102cc9190610652565b60405180910390f35b3480156102e0575f80fd5b506102e96105a2565b6040516102f69190610652565b60405180910390f35b34801561030a575f80fd5b506103136105a8565b604051610320919061082a565b60405180910390f35b348015610334575f80fd5b5061033d610634565b60405161034a9190610652565b60405180910390f35b60045481565b5f8054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600b5f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60075481565b60025481565b60085f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60035481565b60055481565b600860149054906101000a900460e01b81565b6001602052805f5260405f205f915090505481565b5f5b610101811161044f57804361041d9190610877565b4060015f834361042d9190610877565b81526020019081526020015f208190555080610448906108aa565b9050610408565b50415f806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055504460028190555045600381905550436004819055504260058190555046600c819055505f36600691826104c3929190610b22565b505a6007819055503360085f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505f357fffffffff0000000000000000000000000000000000000000000000000000000016600860146101000a81548163ffffffff021916908360e01c0217905550346009819055503a600a8190555032600b5f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b600c5481565b600a5481565b600680546105b590610955565b80601f01602080910402602001604051908101604052809291908181526020018280546105e190610955565b801561062c5780601f106106035761010080835404028352916020019161062c565b820191905f5260205f20905b81548152906001019060200180831161060f57829003601f168201915b505050505081565b60095481565b5f819050919050565b61064c8161063a565b82525050565b5f6020820190506106655f830184610643565b92915050565b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6106948261066b565b9050919050565b6106a48161068a565b82525050565b5f6020820190506106bd5f83018461069b565b92915050565b5f7fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b6106f7816106c3565b82525050565b5f6020820190506107105f8301846106ee565b92915050565b5f80fd5b6107238161063a565b811461072d575f80fd5b50565b5f8135905061073e8161071a565b92915050565b5f6020828403121561075957610758610716565b5b5f61076684828501610730565b91505092915050565b5f819050919050565b6107818161076f565b82525050565b5f60208201905061079a5f830184610778565b92915050565b5f81519050919050565b5f82825260208201905092915050565b5f5b838110156107d75780820151818401526020810190506107bc565b5f8484015250505050565b5f601f19601f8301169050919050565b5f6107fc826107a0565b61080681856107aa565b93506108168185602086016107ba565b61081f816107e2565b840191505092915050565b5f6020820190508181035f83015261084281846107f2565b905092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f6108818261063a565b915061088c8361063a565b92508282039050818111156108a4576108a361084a565b5b92915050565b5f6108b48261063a565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82036108e6576108e561084a565b5b600182019050919050565b5f82905092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f600282049050600182168061096c57607f821691505b60208210810361097f5761097e610928565b5b50919050565b5f819050815f5260205f209050919050565b5f6020601f8301049050919050565b5f82821b905092915050565b5f600883026109e17fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff826109a6565b6109eb86836109a6565b95508019841693508086168417925050509392505050565b5f819050919050565b5f610a26610a21610a1c8461063a565b610a03565b61063a565b9050919050565b5f819050919050565b610a3f83610a0c565b610a53610a4b82610a2d565b8484546109b2565b825550505050565b5f90565b610a67610a5b565b610a72818484610a36565b505050565b5b81811015610a9557610a8a5f82610a5f565b600181019050610a78565b5050565b601f821115610ada57610aab81610985565b610ab484610997565b81016020851015610ac3578190505b610ad7610acf85610997565b830182610a77565b50505b505050565b5f82821c905092915050565b5f610afa5f1984600802610adf565b1980831691505092915050565b5f610b128383610aeb565b9150826002028217905092915050565b610b2c83836108f1565b67ffffffffffffffff811115610b4557610b446108fb565b5b610b4f8254610955565b610b5a828285610a99565b5f601f831160018114610b87575f8415610b75578287013590505b610b7f8582610b07565b865550610be6565b601f198416610b9586610985565b5f5b82811015610bbc57848901358255600182019150602085019450602081019050610b97565b86831015610bd95784890135610bd5601f891682610aeb565b8355505b6001600288020188555050505b5050505050505056fea2646970667358221220b2e1918d734a0a91404c986957651f9fc3b565ef079657229494c330769c740d64736f6c63430008150033"
self.contract_address = self.node.createcontract(bytecode)['address']
print('verify globals in PoW blocks')

self.verify_evm_globals_test(use_staking=True)
self.sync_all()
return
#assert(False)

generatesynchronized(self.node, 257, None, self.nodes)
self.sync_all()
Expand All @@ -223,10 +230,6 @@ def run_test(self):
generatesynchronized(self.node, 257, None, self.nodes)
self.sync_all()

print('verify globals in MPoS blocks')
generatesynchronized(self.node, 4999 - self.node.getblockcount(), None, self.nodes)
self.sync_blocks()

for n in self.nodes:
n.setmocktime((self.node.getblock(self.node.getbestblockhash())['time']+100) & 0xfffffff0)

Expand Down
Loading

0 comments on commit 79d2f5b

Please sign in to comment.