Add EIP165 support

This commit is contained in:
nolash
2021-04-29 08:35:53 +02:00
parent 3241dfa9c5
commit 219c24b624
9 changed files with 144 additions and 9 deletions

62
tests/test_eip165.py Normal file
View File

@@ -0,0 +1,62 @@
# standard imports
import unittest
import os
import logging
# local imports
from chainlib.eth.unittest.ethtester import EthTesterCase
from chainlib.eth.nonce import RPCNonceOracle
from chainlib.eth.gas import OverrideGasOracle
from chainlib.connection import RPCConnection
from chainlib.eth.tx import (
TxFactory,
receipt,
)
from chainlib.eth.eip165 import EIP165
logging.basicConfig(level=logging.DEBUG)
logg = logging.getLogger()
script_dir = os.path.realpath(os.path.dirname(__file__))
class TestSupports(EthTesterCase):
def setUp(self):
super(TestSupports, self).setUp()
#nonce_oracle = TestNonceOracle(self.accounts[0])
self.conn = RPCConnection.connect(self.chain_spec, 'default')
nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn)
f = open(os.path.join(script_dir, 'testdata', 'Supports.bin'))
code = f.read()
f.close()
txf = TxFactory(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
tx = txf.template(self.accounts[0], None, use_nonce=True)
tx = txf.set_code(tx, code)
(tx_hash_hex, o) = txf.build(tx)
r = self.conn.do(o)
logg.debug('deployed with hash {}'.format(r))
o = receipt(tx_hash_hex)
r = self.conn.do(o)
self.address = r['contract_address']
def test_supports(self):
gas_oracle = OverrideGasOracle(limit=100000, conn=self.conn)
c = EIP165(self.chain_spec, gas_oracle=gas_oracle)
o = c.supports_interface(self.address, '0xdeadbeef', sender_address=self.accounts[0])
r = self.conn.do(o)
v = c.parse_supports_interface(r)
self.assertEqual(v, 1)
o = c.supports_interface(self.address, '0xbeeffeed', sender_address=self.accounts[0])
r = self.conn.do(o)
v = c.parse_supports_interface(r)
self.assertEqual(v, 0)
if __name__ == '__main__':
unittest.main()

1
tests/testdata/Supports.bin vendored Normal file
View File

@@ -0,0 +1 @@
608060405234801561001057600080fd5b506101c9806100206000396000f3fe608060405234801561001057600080fd5b5060043610610048576000357c01000000000000000000000000000000000000000000000000000000009004806301ffc9a71461004d575b600080fd5b610067600480360381019061006291906100f1565b61007d565b6040516100749190610129565b60405180910390f35b600063deadbeef7c010000000000000000000000000000000000000000000000000000000002827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614156100d257600190506100d7565b600090505b919050565b6000813590506100eb8161017c565b92915050565b60006020828403121561010357600080fd5b6000610111848285016100dc565b91505092915050565b61012381610144565b82525050565b600060208201905061013e600083018461011a565b92915050565b60008115159050919050565b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b61018581610150565b811461019057600080fd5b5056fea264697066735822122073144ec34d71a86680325f1aee9a3b9041e22c422e7b1b82d409b303d52192de64736f6c63430008030033

10
tests/testdata/Supports.sol vendored Normal file
View File

@@ -0,0 +1,10 @@
pragma solidity ^0.8.0;
contract Supports {
function supportsInterface(bytes4 _sum) public pure returns (bool) {
if (_sum == 0xdeadbeef) {
return true;
}
return false;
}
}