def _(properties, defaults=None) -> RefundTransfer: params, signer = prepare_locked_transfer(properties, defaults) transfer = RefundTransfer(**params) transfer.sign(signer) assert params["sender"] == transfer.sender return transfer
def test_decode_refund_transfer(settle_timeout, tester_state, tester_token): privatekey0 = tester.DEFAULT_KEY privatekey1 = tester.k1 address0 = privatekey_to_address(privatekey0) address1 = privatekey_to_address(privatekey1) dtester = deploy_decoder_tester(tester_state, tester_token.address, address0, address1, settle_timeout) locksroot = sha3('Mainz') amount = 1337 expiration = 19 lock = Lock(amount, expiration, locksroot) message = RefundTransfer(identifier=321313, nonce=4242452, token=tester_token.address, transferred_amount=amount, recipient=address1, locksroot=locksroot, lock=lock) message.sign(PrivateKey(privatekey0, ctx=GLOBAL_CTX, raw=True), address0) _, publickey = wrap_and_validate(message.encode()) recovered_address = address_from_key(publickey) assert recovered_address == address0 assert dtester.testDecodeTransfer(message.encode(), sender=privatekey1) is True assert dtester.decodedNonce() == 4242452 assert dtester.decodedToken() == tester_token.address.encode('hex') assert dtester.decodedLocksroot() == locksroot
def test_cancel_transfer(iterations=ITERATIONS): amount = 1 expiration = 1 hashlock = sha3(ADDRESS) lock = Lock(amount, expiration, hashlock) nonce = 1 asset = ADDRESS balance = 1 recipient = ADDRESS locksroot = sha3(ADDRESS) msg = RefundTransfer(nonce, asset, balance, recipient, locksroot, lock) msg.sign(PRIVKEY) run_timeit('RefundTransfer', msg, iterations=iterations)
def test_decode_refund_transfer( private_keys, settle_timeout, tester_state, tester_token, tester_events, tester_registry): privatekey0 = tester.DEFAULT_KEY privatekey1 = private_keys[1] address0 = privatekey_to_address(privatekey0) address1 = privatekey_to_address(privatekey1) dtester = deploy_decoder_tester(tester_token.address, address0, address1, settle_timeout) locksroot = sha3("Mainz") amount = 1337 expiration = 19 lock = Lock(amount, expiration, locksroot) message = RefundTransfer( identifier=321313, nonce=4242452, asset=tester_token.address, transferred_amount=amount, recipient=address1, locksroot=locksroot, lock=lock ) message.sign(PrivateKey(privatekey0, ctx=GLOBAL_CTX, raw=True), address0) _, publickey = wrap_and_validate(message.encode()) recovered_address = address_from_key(publickey) assert recovered_address == address0 assert dtester.testDecodeTransfer(message.encode()) is True assert dtester.decodedNonce() == 4242452 assert dtester.decodedExpiration() == expiration assert dtester.decodedAsset() == tester_token.address.encode('hex') assert dtester.decodedRecipient() == address1.encode('hex') assert dtester.decodedAmount() == amount assert dtester.decodedLocksroot() == locksroot
def test_cancel_transfer(iterations=ITERATIONS): amount = 1 expiration = 1 hashlock = sha3(ADDRESS) lock = Lock(amount, expiration, hashlock) identifier = 1 nonce = 1 asset = ADDRESS transferred_amount = 1 recipient = ADDRESS locksroot = sha3(ADDRESS) msg = RefundTransfer( identifier, nonce, asset, transferred_amount, recipient, locksroot, lock, ) msg.sign(PRIVKEY, ADDRESS) run_timeit('RefundTransfer', msg, iterations=iterations)