def test_verifyBalanceProof(web3, token_contract, channels_contract): (A, B) = web3.eth.accounts[:2] challenge_period = 5 supply = 10000 * 10**18 token = token_contract([supply, "CustomToken", "TKN", 18]) contract = channels_contract([token.address, challenge_period]) signer = '0x5601ea8445a5d96eeebf89a67c4199fbb7a43fbb' receiver = '0x5601ea8445a5d96eeebf89a67c4199fbb7a43fbb' block = 4804175 balance = 22000000000000000000 balance_msg_sig = '0x1803dfc1e597c08f0cc3f6e39fb109f6497c2b5321deb656f54567981889fddb49c82a33ecae2b1ae86f2fb50f0929cbad097502f8c04c7bfb8ae51883d3e1371b' balance_msg_sig = bytes.fromhex(balance_msg_sig[2:]) signature_address = contract.call().verifyBalanceProof( receiver, block, balance, balance_msg_sig) assert signature_address == signer balance_message_hash = balance_proof_hash(B, block, balance) balance_msg_sig, addr = sign.check(balance_message_hash, tester.k0) assert addr == A signature_address = contract.call().verifyBalanceProof( B, block, balance, balance_msg_sig) assert signature_address == A
def test_channel_223_create(web3, chain, contract, channels_contract): (Owner, A, B, C, D) = web3.eth.accounts[:5] other_contract = channels_contract([token.address, 10], {'from': D}) depozit_B = 100 depozit_D = 120 # Allocate some tokens first token.transact({"from": Owner}).transfer(B, depozit_B) token.transact({"from": Owner}).transfer(D, depozit_D) assert token.call().balanceOf(B) == depozit_B assert token.call().balanceOf(D) == depozit_D assert token.call().balanceOf(contract.address) == 0 # address - 20 bytes txdata = A[2:].zfill(40) print('----A', A, txdata) txdata = bytes.fromhex(txdata) #with pytest.raises(tester.TransactionFailed): # token.transact({"from": B}).transfer(other_contract.address, depozit_B, txdata) with pytest.raises(TypeError): token.transact({"from": B}).transfer(contract.address, -2, txdata) # TODO should this fail? #token.transact({"from": B}).transfer(contract.address, depozit_B, A_bytes_fake) #A_bytes = '0x829bd824b016326a401d083b33d092293333a830' trxid = token.transact({"from": B}).transfer(contract.address, depozit_B, txdata) channel_post_create_tests(contract, B, A, depozit_B) print('----------------------------------') print('GAS USED test_channel_223_create', get_gas_used(chain, trxid)) print('----------------------------------')
def contract(chain, web3, token_contract, channels_contract, decimals): global token global logs global challenge_period challenge_period = 5 logs = {} supply = 10000 * 10**(decimals) token = token_contract([supply, "CustomToken", "TKN", decimals]) contract = channels_contract([token.address, challenge_period]) return contract
def test_version(web3, contract, channels_contract): (Owner, A) = web3.eth.accounts[:2] other_contract = channels_contract([token.address, 10], {'from': A}) assert contract.call().version() == uraiden_contract_version assert contract.call().latest_version_address() == '0x0000000000000000000000000000000000000000' with pytest.raises(TypeError): contract.transact({'from': Owner}).setLatestVersionAddress('0x') with pytest.raises(TypeError): contract.transact({'from': Owner}).setLatestVersionAddress(123) with pytest.raises(tester.TransactionFailed): contract.transact({'from': Owner}).setLatestVersionAddress(A) with pytest.raises(tester.TransactionFailed): contract.transact({'from': A}).setLatestVersionAddress(other_contract.address) contract.transact({'from': Owner}).setLatestVersionAddress(other_contract.address) assert contract.call().latest_version_address() == other_contract.address