erc20-transfer-authorization

Simple approval escrow for ERC20 spending
Log | Files | Refs

commit ea8b875065e273738456e050407ce06cdc609ce1
parent a1ff96561cc1a5b48d2f3aff378af767a88ee7d4
Author: lash <dev@holbrook.no>
Date:   Sat, 10 Dec 2022 10:28:09 +0000

Add threshold bounds tests

Diffstat:
Mpython/erc20_transfer_authorization/transfer_authorization.py | 35++++++++++++++++++++++++++++++++++-
Dpython/tests/test_app.py | 222-------------------------------------------------------------------------------
Apython/tests/test_basic.py | 123+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mpython/tests/test_quorum.py | 168++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Mpython/tests/test_transfer.py | 60+++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
5 files changed, 380 insertions(+), 228 deletions(-)

diff --git a/python/erc20_transfer_authorization/transfer_authorization.py b/python/erc20_transfer_authorization/transfer_authorization.py @@ -68,6 +68,14 @@ class Request: return self.result & 24 == 8 + def is_voting(self): + return self.result & 7 == 1 + + + def is_executed(self): + return self.result & 8 == 8 + + def __str__(self): return "{} {} {} {}".format(self.sender, self.recipient, self.value, self.result) @@ -77,7 +85,27 @@ class TransferAuthorization(TxFactory): __abi = None __bytecode = None - + + + def __init__(self, *args, **kwargs): + super(TransferAuthorization, self).__init__(*args, **kwargs) + + + def count(self, *args, **kwargs): + return self.call_noarg('count', *args, **kwargs) + + + def quorum_threshold(self, *args, **kwargs): + return self.call_noarg('quorum', *args, **kwargs) + + + def veto_threshold(self, *args, **kwargs): + return self.call_noarg('vetoThreshold', *args, **kwargs) + + + def signer_count(self, *args, **kwargs): + return self.call_noarg('signerCount', *args, **kwargs) + @staticmethod def abi(): @@ -254,6 +282,11 @@ class TransferAuthorization(TxFactory): @classmethod + def parse_count(self, v): + return abi_decode_single(ABIContractType.UINT32, v) + + + @classmethod def parse_create_request_request(self, v): v = strip_0x(v) cursor = 0 diff --git a/python/tests/test_app.py b/python/tests/test_app.py @@ -1,222 +0,0 @@ -# standard imports -import os -import unittest -import logging - -# external imports -from chainlib.eth.nonce import RPCNonceOracle -from chainlib.eth.tx import receipt - -# local imports -from erc20_transfer_authorization import TransferAuthorization - -# testutil imports -from tests.base_erc20transferauthorization import TestBase - -logg = logging.getLogger() - -testdir = os.path.dirname(__file__) - - -class TestBasic(TestBase): - - def setUp(self): - super(TestBasic, self).setUp() - nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc) - self.c = TransferAuthorization(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) - (tx_hash_hex, o) = self.c.add_writer(self.address, self.accounts[0], self.accounts[1]) - 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.add_writer(self.address, self.accounts[0], self.accounts[2]) - self.rpc.do(o) - o = receipt(tx_hash_hex) - r = self.rpc.do(o) - self.assertEqual(r['status'], 1) - - - def test_basic(self): - c = TransferAuthorization(self.chain_spec) - - o = c.is_writer(self.address, self.accounts[0], sender_address=self.accounts[0]) - r = self.rpc.do(o) - self.assertTrue(c.parse_signers(r)) - - o = c.is_writer(self.address, self.accounts[1], sender_address=self.accounts[0]) - r = self.rpc.do(o) - self.assertTrue(c.parse_signers(r)) - - o = c.is_writer(self.address, self.accounts[2], sender_address=self.accounts[0]) - r = self.rpc.do(o) - self.assertTrue(c.parse_signers(r)) - - o = c.is_writer(self.address, self.accounts[3], sender_address=self.accounts[0]) - r = self.rpc.do(o) - self.assertFalse(c.parse_signers(r)) - - - def test_limit(self): - nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc) - c = TransferAuthorization(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) - - (tx_hash_hex, o) = 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) = 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) = 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) - - (tx_hash_hex, o) = c.yay(self.address, self.accounts[0], 2) - self.rpc.do(o) - o = receipt(tx_hash_hex) - r = self.rpc.do(o) - self.assertEqual(r['status'], 1) - - o = self.c.check_result(self.address, 1, sender_address=self.accounts[0]) - self.rpc.do(o) - print(o) - - -# def test_get(self): -# w = self.w3.eth.contract(abi=self.abi_wallet, address=self.address_wallet) -# t = self.w3.eth.contract(abi=self.abi_token, address=self.address_token) -# -# tx_hash = w.functions.createRequest(self.w3.eth.accounts[2], self.w3.eth.accounts[3], t.address, 10).transact({'from': self.w3.eth.accounts[9]}) -# r = self.w3.eth.getTransactionReceipt(tx_hash) -# -# topic_match = 'b609ae609609ee99268d05bc1371102cafe8d6b964bf082439ab16be2a01c87c' -# log = r.logs[0] -# topic = log.topics[0] -# self.assertEqual(topic.hex()[2:], topic_match) -# serial = int(log.data[66:], 16) -# -# for i in range(1, 3): -# tx_hash = w.functions.createRequest(self.w3.eth.accounts[2], self.w3.eth.accounts[3+i], t.address, 10*(i+1)).transact({'from': self.w3.eth.accounts[2]}) -# -# tq_count = w.functions.count().call() -# assert (tq_count == 3); -# -# for i in range(w.functions.nextSerial().call(), w.functions.lastSerial().call()): -# tqg = w.functions.requests(i).call() -# -# self.assertEqual(tqg[0], i) -# self.assertEqual(tqg[1], self.w3.eth.accounts[2]) -# self.assertEqual(tqg[2], self.w3.eth.accounts[3+(i-1)]) -# self.assertEqual(tqg[3], t.address) -# self.assertEqual(tqg[4], 10*i) -# -# -# def test_get_vote(self): -# w = self.w3.eth.contract(abi=self.abi_wallet, address=self.address_wallet) -# t = self.w3.eth.contract(abi=self.abi_token, address=self.address_token) -# -# tx_hash = w.functions.createRequest(self.w3.eth.accounts[2], self.w3.eth.accounts[3], t.address, 10).transact({'from': self.w3.eth.accounts[9]}) -# w.functions.nay(1).transact({'from': self.w3.eth.accounts[0]}) -# -# self.assertEqual(w.functions.voters(1, 0).call(), self.w3.eth.accounts[0]) -# self.assertEqual(w.functions.vote(1, self.w3.eth.accounts[0]).call(), -1) -# -# -# def test_indexes(self): -# w = self.w3.eth.contract(abi=self.abi_wallet, address=self.address_wallet) -# t = self.w3.eth.contract(abi=self.abi_token, address=self.address_token) -# -# for i in range(0, 5): -# amount = 10*(i+1) -# sender = self.w3.eth.accounts[3+i]; -# tx_hash = w.functions.createRequest(self.w3.eth.accounts[2], sender, t.address, amount).transact({'from': self.w3.eth.accounts[2]}) -# -# w.functions.nay(1).transact({'from': self.w3.eth.accounts[0]}) -# w.functions.nay(4).transact({'from': self.w3.eth.accounts[0]}) -# -# self.assertEqual(w.functions.getSerialAt(0).call(), 2) -# self.assertEqual(w.functions.getSerialAt(1).call(), 3) -# self.assertEqual(w.functions.getSerialAt(2).call(), 5) -# -# -# def test_index_after_removal(self): -# w = self.w3.eth.contract(abi=self.abi_wallet, address=self.address_wallet) -# t = self.w3.eth.contract(abi=self.abi_token, address=self.address_token) -# -# for i in range(0, 4): -# amount = 10*(i+1) -# sender = self.w3.eth.accounts[3+i]; -# tx_hash = w.functions.createRequest(self.w3.eth.accounts[2], sender, t.address, amount).transact({'from': self.w3.eth.accounts[2]}) -# -# tq_count = w.functions.count().call() -# self.assertEqual(tq_count, 4); -# self.assertEqual(w.functions.lastSerial().call(), 4) -# self.assertEqual(w.functions.nextSerial().call(), 1) -# -# w.functions.nay(2).transact({'from': self.w3.eth.accounts[0]}) -# self.assertEqual(w.functions.count().call(), 3) -# self.assertEqual(w.functions.nextSerial().call(), 1) -# self.assertEqual(w.functions.lastSerial().call(), 4) -# -# w.functions.nay(1).transact({'from': self.w3.eth.accounts[0]}) -# self.assertEqual(w.functions.count().call(), 2) -# self.assertEqual(w.functions.nextSerial().call(), 3) -# self.assertEqual(w.functions.lastSerial().call(), 4) -# -# w.functions.createRequest(self.w3.eth.accounts[2], self.w3.eth.accounts[3], t.address, 42).transact({'from': self.w3.eth.accounts[2]}) -# self.assertEqual(w.functions.count().call(), 3) -# self.assertEqual(w.functions.lastSerial().call(), 5) -# self.assertEqual(w.functions.nextSerial().call(), 3) -# -# w.functions.nay(3).transact({'from': self.w3.eth.accounts[0]}) -# self.assertEqual(w.functions.count().call(), 2) -# self.assertEqual(w.functions.lastSerial().call(), 5) -# self.assertEqual(w.functions.nextSerial().call(), 4) -# -# w.functions.nay(4).transact({'from': self.w3.eth.accounts[0]}) -# self.assertEqual(w.functions.count().call(), 1) -# self.assertEqual(w.functions.nextSerial().call(), 5) -# self.assertEqual(w.functions.lastSerial().call(), 5) -# -# w.functions.nay(5).transact({'from': self.w3.eth.accounts[0]}) -# self.assertEqual(w.functions.count().call(), 0) -# self.assertEqual(w.functions.nextSerial().call(), 0) -# self.assertEqual(w.functions.lastSerial().call(), 5) -# -# -# def test_pass_on_insufficient_approve(self): -# w = self.w3.eth.contract(abi=self.abi_wallet, address=self.address_wallet) -# t = self.w3.eth.contract(abi=self.abi_token, address=self.address_token) -# -# self.eth_tester.mine_block() -# -# w.functions.createRequest(self.w3.eth.accounts[2], self.w3.eth.accounts[3], t.address, 10).transact({'from': self.w3.eth.accounts[2]}) -# w.functions.yay(1).transact({'from': self.w3.eth.accounts[0]}) -# self.eth_tester.mine_block() -# -# tx_hash = w.functions.executeRequest(1).transact({'from': self.w3.eth.accounts[0]}) -# -# r = self.w3.eth.getTransactionReceipt(tx_hash) -# -# topic_match = 'dab20a0fcd702cf875c2d715d5c3fc99af66a716c94b3405408c94b7311c99eb' # TransferFail(uint256) -# log = r.logs[0] -# topic = log.topics[0] -# self.assertEqual(topic.hex()[2:], topic_match) -# serial = int(log.data[2:], 16) -# -# self.assertEqual(serial, 1) -# -# self.assertEqual(w.functions.count().call(), 0) -# self.assertEqual(w.functions.nextSerial().call(), 0) - - -if __name__ == '__main__': - unittest.main() diff --git a/python/tests/test_basic.py b/python/tests/test_basic.py @@ -0,0 +1,123 @@ +# standard imports +import os +import unittest +import logging + +# external imports +from chainlib.eth.nonce import RPCNonceOracle +from chainlib.eth.tx import receipt + +# local imports +from erc20_transfer_authorization import TransferAuthorization + +# testutil imports +from tests.base_erc20transferauthorization import TestBase + +logg = logging.getLogger() + +testdir = os.path.dirname(__file__) + + +class TestBasic(TestBase): + + def setUp(self): + super(TestBasic, self).setUp() + nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc) + self.c = TransferAuthorization(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) + (tx_hash_hex, o) = self.c.add_writer(self.address, self.accounts[0], self.accounts[1]) + 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.add_writer(self.address, self.accounts[0], self.accounts[2]) + self.rpc.do(o) + o = receipt(tx_hash_hex) + r = self.rpc.do(o) + self.assertEqual(r['status'], 1) + + + def test_basic(self): + c = TransferAuthorization(self.chain_spec) + + o = c.is_writer(self.address, self.accounts[0], sender_address=self.accounts[0]) + r = self.rpc.do(o) + self.assertTrue(c.parse_signers(r)) + + o = c.is_writer(self.address, self.accounts[1], sender_address=self.accounts[0]) + r = self.rpc.do(o) + self.assertTrue(c.parse_signers(r)) + + o = c.is_writer(self.address, self.accounts[2], sender_address=self.accounts[0]) + r = self.rpc.do(o) + self.assertTrue(c.parse_signers(r)) + + o = c.is_writer(self.address, self.accounts[3], sender_address=self.accounts[0]) + r = self.rpc.do(o) + self.assertFalse(c.parse_signers(r)) + + o = c.signer_count(self.address, sender_address=self.accounts[0]) + r = self.rpc.do(o) + count = c.parse_count(r) + self.assertEqual(count, 3) + + +# def test_limit(self): +# nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc) +# c = TransferAuthorization(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) +# +# (tx_hash_hex, o) = 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) = 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) = 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) +# +# (tx_hash_hex, o) = c.yay(self.address, self.accounts[0], 2) +# self.rpc.do(o) +# o = receipt(tx_hash_hex) +# r = self.rpc.do(o) +# self.assertEqual(r['status'], 1) +# +# (tx_hash_hex, o) = c.check_result(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) +# +# o = c.requests(self.address, 1, sender_address=self.accounts[0]) +# r = self.rpc.do(o) +# request = self.c.parse_request(r) +# logg.debug('request {}'.format(request)) +# self.assertTrue(request.is_accepted()) + + + def test_serial(self): + nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc) + c = TransferAuthorization(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) + for i in range(5): + (tx_hash_hex, o) = c.create_request(self.address, self.accounts[0], self.accounts[i], self.accounts[i+1], self.token_address, 1024 * i) + self.rpc.do(o) + o = receipt(tx_hash_hex) + r = self.rpc.do(o) + self.assertEqual(r['status'], 1) + + o = c.count(self.address, sender_address=self.accounts[0]) + r = self.rpc.do(o) + count = c.parse_count(r) + self.assertEqual(count, 5) + + +if __name__ == '__main__': + unittest.main() diff --git a/python/tests/test_quorum.py b/python/tests/test_quorum.py @@ -35,13 +35,76 @@ class TestQuorum(TestBase): self.assertEqual(r['status'], 1) - def test_register(self): - (tx_hash_hex, o) = self.c.set_thresholds(self.address, self.accounts[0], 2, 2) + def test_basic(self): + o = self.c.quorum_threshold(self.address, sender_address=self.accounts[0]) + r = self.rpc.do(o) + count = self.c.parse_count(r) + self.assertEqual(count, 1) + + o = self.c.veto_threshold(self.address, sender_address=self.accounts[0]) + r = self.rpc.do(o) + count = self.c.parse_count(r) + self.assertEqual(count, 0) + + (tx_hash_hex, o) = self.c.set_thresholds(self.address, self.accounts[0], 3, 1) self.rpc.do(o) o = receipt(tx_hash_hex) r = self.rpc.do(o) self.assertEqual(r['status'], 1) + o = self.c.quorum_threshold(self.address, sender_address=self.accounts[0]) + r = self.rpc.do(o) + count = self.c.parse_count(r) + self.assertEqual(count, 3) + + o = self.c.veto_threshold(self.address, sender_address=self.accounts[0]) + r = self.rpc.do(o) + count = self.c.parse_count(r) + self.assertEqual(count, 1) + + + def test_signer_sanity(self): + (tx_hash_hex, o) = self.c.set_thresholds(self.address, self.accounts[0], 0, 0) + self.rpc.do(o) + o = receipt(tx_hash_hex) + r = self.rpc.do(o) + self.assertEqual(r['status'], 0) + + (tx_hash_hex, o) = self.c.set_thresholds(self.address, self.accounts[0], 0, 1) + self.rpc.do(o) + o = receipt(tx_hash_hex) + r = self.rpc.do(o) + self.assertEqual(r['status'], 0) + + (tx_hash_hex, o) = self.c.set_thresholds(self.address, self.accounts[0], 5, 0) + 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.set_thresholds(self.address, self.accounts[0], 6, 0) + self.rpc.do(o) + o = receipt(tx_hash_hex) + r = self.rpc.do(o) + self.assertEqual(r['status'], 0) + + (tx_hash_hex, o) = self.c.set_thresholds(self.address, self.accounts[0], 5, 5) + 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.set_thresholds(self.address, self.accounts[0], 5, 6) + self.rpc.do(o) + o = receipt(tx_hash_hex) + r = self.rpc.do(o) + self.assertEqual(r['status'], 0) + + + def test_register(self): + (tx_hash_hex, o) = self.c.set_thresholds(self.address, self.accounts[0], 2, 2) + self.rpc.do(o) + (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) @@ -71,6 +134,39 @@ class TestQuorum(TestBase): r = self.rpc.do(o) self.assertEqual(r['status'], 1) + + def test_veto(self): + (tx_hash_hex, o) = self.c.set_thresholds(self.address, self.accounts[0], 1, 1) + 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'], 0) + + 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()) + def test_simple_yay(self): (tx_hash_hex, o) = self.c.set_thresholds(self.address, self.accounts[0], 2, 2) @@ -222,6 +318,12 @@ class TestQuorum(TestBase): r = self.rpc.do(o) self.assertEqual(r['status'], 0) + o = self.c.requests(self.address, 1, sender_address=self.accounts[0]) + r = self.rpc.do(o) + request = self.c.parse_request(r) + logg.debug('request {}'.format(request)) + self.assertTrue(request.is_accepted()) + def test_nay_yay_nay(self): (tx_hash_hex, o) = self.c.set_thresholds(self.address, self.accounts[0], 2, 2) @@ -307,6 +409,12 @@ class TestQuorum(TestBase): r = self.rpc.do(o) self.assertEqual(r['status'], 0) + o = self.c.requests(self.address, 1, sender_address=self.accounts[0]) + r = self.rpc.do(o) + request = self.c.parse_request(r) + logg.debug('request {}'.format(request)) + self.assertTrue(request.is_rejected()) + def test_nay_yay_nay_nay(self): (tx_hash_hex, o) = self.c.set_thresholds(self.address, self.accounts[0], 2, 2) @@ -351,6 +459,62 @@ class TestQuorum(TestBase): r = self.rpc.do(o) self.assertEqual(r['status'], 0) + o = self.c.requests(self.address, 1, sender_address=self.accounts[0]) + r = self.rpc.do(o) + request = self.c.parse_request(r) + logg.debug('request {}'.format(request)) + self.assertTrue(request.is_rejected()) + + + def test_nay_majority(self): + (tx_hash_hex, o) = self.c.set_thresholds(self.address, self.accounts[0], 3, 0) + 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.nay(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) + + 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) + + o = self.c.requests(self.address, 1, sender_address=self.accounts[0]) + r = self.rpc.do(o) + request = self.c.parse_request(r) + logg.debug('request {}'.format(request)) + self.assertTrue(request.is_rejected()) + if __name__ == '__main__': unittest.main() diff --git a/python/tests/test_transfer.py b/python/tests/test_transfer.py @@ -44,24 +44,71 @@ class TestTransfer(TestBase): self.assertEqual(r['status'], 1) - def test_transfer(self): + def test_premature_transfer(self): (tx_hash_hex, o) = self.c.create_request(self.address, self.accounts[0], self.accounts[9], 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) + (tx_hash_hex, o) = self.c.check_result(self.address, self.accounts[0], 1) + r = 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.execute_request(self.address, self.accounts[0], 1) + r = self.rpc.do(o) + o = receipt(tx_hash_hex) + r = self.rpc.do(o) + self.assertEqual(r['status'], 0) + + 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_voting()) + self.assertFalse(request.is_executed()) + + + def test_reject_transfer(self): + (tx_hash_hex, o) = self.c.create_request(self.address, self.accounts[0], self.accounts[9], 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.set_thresholds(self.address, self.accounts[0], 1, 1) + self.rpc.do(o) + + (tx_hash_hex, o) = self.c.nay(self.address, self.accounts[0], 1) + self.rpc.do(o) + (tx_hash_hex, o) = self.c.check_result(self.address, self.accounts[0], 1) r = self.rpc.do(o) + + (tx_hash_hex, o) = self.c.execute_request(self.address, self.accounts[0], 1) + r = self.rpc.do(o) o = receipt(tx_hash_hex) r = self.rpc.do(o) - self.assertEqual(r['status'], 1) + self.assertEqual(r['status'], 0) + + 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()) + self.assertFalse(request.is_voting()) + self.assertFalse(request.is_executed()) + + + def test_transfer(self): + (tx_hash_hex, o) = self.c.create_request(self.address, self.accounts[0], self.accounts[9], self.accounts[2], self.token_address, 1024) + self.rpc.do(o) + + (tx_hash_hex, o) = self.c.yay(self.address, self.accounts[0], 1) + self.rpc.do(o) + + (tx_hash_hex, o) = self.c.check_result(self.address, self.accounts[0], 1) + r = self.rpc.do(o) (tx_hash_hex, o) = self.c.execute_request(self.address, self.accounts[0], 1) r = self.rpc.do(o) @@ -74,6 +121,7 @@ class TestTransfer(TestBase): request = self.c.parse_request(r) logg.debug('request {}'.format(request)) self.assertTrue(request.is_transferred()) + self.assertTrue(request.is_executed()) nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc) c = ERC20(self.chain_spec, nonce_oracle=nonce_oracle) @@ -82,6 +130,12 @@ class TestTransfer(TestBase): balance = c.parse_balance(r) self.assertEqual(balance, 10000-1024) + (tx_hash_hex, o) = self.c.execute_request(self.address, self.accounts[0], 1) + r = self.rpc.do(o) + o = receipt(tx_hash_hex) + r = self.rpc.do(o) + self.assertEqual(r['status'], 0) + if __name__ == '__main__': unittest.main()