erc20-transfer-authorization

Simple approval escrow for ERC20 spending
Log | Files | Refs

commit 36c5d871c2a08bfb0581d00d5d9d118c2b3cd437
parent 7858cad57c0211829eb71ceb83a42824913bd391
Author: lash <dev@holbrook.no>
Date:   Thu,  8 Dec 2022 19:37:48 +0000

Add tests for base quorum and veto

Diffstat:
Mpython/erc20_transfer_authorization/transfer_authorization.py | 14--------------
Mpython/tests/test_quorum.py | 77+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 77 insertions(+), 14 deletions(-)

diff --git a/python/erc20_transfer_authorization/transfer_authorization.py b/python/erc20_transfer_authorization/transfer_authorization.py @@ -286,17 +286,3 @@ class TransferAuthorization(TxFactory): cursor += 64 r = d.decode() return Request.create(r[1], r[2], r[0], r[3], r[4], r[5], r[6], r[7]) - -# -# def last_serial(self): -# return self.contract.functions.lastSerial().call() -# -# def requests(self, idx): -# req = self.contract.functions.requests(idx).call() -# return { -# 'serial': req[0], -# 'sender': req[1], -# 'recipient': req[2], -# 'token': req[3], -# 'value': req[4], -# } diff --git a/python/tests/test_quorum.py b/python/tests/test_quorum.py @@ -187,5 +187,82 @@ class TestQuorum(TestBase): self.assertTrue(request.is_accepted()) + def test_yay_yay_nay(self): + (tx_hash_hex, o) = self.c.set_thresholds(self.address, self.accounts[0], 2, 2) + self.rpc.do(o) + o = receipt(tx_hash_hex) + r = self.rpc.do(o) + self.assertEqual(r['status'], 1) + + (tx_hash_hex, o) = self.c.create_request(self.address, self.accounts[0], self.accounts[1], self.accounts[2], self.token_address, 1024) + self.rpc.do(o) + o = receipt(tx_hash_hex) + r = self.rpc.do(o) + self.assertEqual(r['status'], 1) + + (tx_hash_hex, o) = self.c.yay(self.address, self.accounts[0], 1) + self.rpc.do(o) + o = receipt(tx_hash_hex) + r = self.rpc.do(o) + self.assertEqual(r['status'], 1) + + nonce_oracle = RPCNonceOracle(self.accounts[1], self.rpc) + c = TransferAuthorization(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) + (tx_hash_hex, o) = c.yay(self.address, self.accounts[1], 1) + self.rpc.do(o) + o = receipt(tx_hash_hex) + r = self.rpc.do(o) + self.assertEqual(r['status'], 1) + + nonce_oracle = RPCNonceOracle(self.accounts[2], self.rpc) + c = TransferAuthorization(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) + (tx_hash_hex, o) = c.nay(self.address, self.accounts[2], 1) + self.rpc.do(o) + o = receipt(tx_hash_hex) + r = self.rpc.do(o) + self.assertEqual(r['status'], 0) + + + def test_nay_yay_nay(self): + (tx_hash_hex, o) = self.c.set_thresholds(self.address, self.accounts[0], 2, 2) + self.rpc.do(o) + o = receipt(tx_hash_hex) + r = self.rpc.do(o) + self.assertEqual(r['status'], 1) + + (tx_hash_hex, o) = self.c.create_request(self.address, self.accounts[0], self.accounts[1], self.accounts[2], self.token_address, 1024) + self.rpc.do(o) + o = receipt(tx_hash_hex) + r = self.rpc.do(o) + self.assertEqual(r['status'], 1) + + (tx_hash_hex, o) = self.c.nay(self.address, self.accounts[0], 1) + self.rpc.do(o) + o = receipt(tx_hash_hex) + r = self.rpc.do(o) + self.assertEqual(r['status'], 1) + + nonce_oracle = RPCNonceOracle(self.accounts[1], self.rpc) + c = TransferAuthorization(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) + (tx_hash_hex, o) = c.yay(self.address, self.accounts[1], 1) + self.rpc.do(o) + o = receipt(tx_hash_hex) + r = self.rpc.do(o) + self.assertEqual(r['status'], 1) + + nonce_oracle = RPCNonceOracle(self.accounts[2], self.rpc) + c = TransferAuthorization(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) + (tx_hash_hex, o) = c.nay(self.address, self.accounts[2], 1) + self.rpc.do(o) + o = receipt(tx_hash_hex) + r = self.rpc.do(o) + self.assertEqual(r['status'], 1) + + o = self.c.requests(self.address, 1, sender_address=self.accounts[0]) + r = self.rpc.do(o) + request = self.c.parse_request(r) + self.assertTrue(request.is_rejected()) + + if __name__ == '__main__': unittest.main()