commit 80e090ec2584f34379386800d639878521b43c77
parent 93da1d66bb9e29a27e693f4bac8114e02c607ae7
Author: lash <dev@holbrook.no>
Date: Thu, 8 Dec 2022 19:24:46 +0000
Add test for veto before quoroum
Diffstat:
2 files changed, 73 insertions(+), 3 deletions(-)
diff --git a/python/erc20_transfer_authorization/transfer_authorization.py b/python/erc20_transfer_authorization/transfer_authorization.py
@@ -42,7 +42,7 @@ class Request:
self.serial = 0
self.yay = 0
self.nay = 0
- self.result = False
+ self.result = 0
@classmethod
@@ -52,10 +52,19 @@ class Request:
o.serial = args[0]
o.yay = args[1]
o.nsy = args[2]
- o.result = args[3] & 2 > 0
+ o.result = args[3]
return o
+ def is_accepted(self):
+ return self.result & 2 > 0
+
+
+ def is_rejected(self):
+ return self.result & 4 > 0
+
+
+
class TransferAuthorization(TxFactory):
__abi = None
@@ -167,6 +176,18 @@ class TransferAuthorization(TxFactory):
return tx
+ def nay(self, contract_address, sender_address, serial, tx_format=TxFormat.JSONRPC):
+ enc = ABIContractEncoder()
+ enc.method('nay')
+ enc.typ(ABIContractType.UINT32)
+ enc.uintn(serial, 32)
+ data = enc.get()
+ tx = self.template(sender_address, contract_address, use_nonce=True)
+ tx = self.set_code(tx, data)
+ tx = self.finalize(tx, tx_format)
+ return tx
+
+
def constructor(self, sender_address):
code = TransferAuthorization.bytecode()
tx = self.template(sender_address, None, use_nonce=True)
diff --git a/python/tests/test_quorum.py b/python/tests/test_quorum.py
@@ -92,10 +92,59 @@ class TestQuorum(TestBase):
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)
+
+ 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_accepted())
+
+
+ def test_nay_before_yay(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.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)
+
o = self.c.requests(self.address, 1, sender_address=self.accounts[0])
r = self.rpc.do(o)
request = self.c.parse_request(r)
- self.assertFalse(request.result)
+ self.assertFalse(request.is_accepted())
if __name__ == '__main__':