|
| 1 | +from crypto.transactions.builder.token_approve_builder import ( |
| 2 | + TokenApproveBuilder, |
| 3 | +) |
| 4 | + |
| 5 | + |
| 6 | +def test_token_approve_transaction(passphrase, load_transaction_fixture): |
| 7 | + fixture = load_transaction_fixture('transactions/token-approve') |
| 8 | + |
| 9 | + builder = ( |
| 10 | + TokenApproveBuilder |
| 11 | + .new() |
| 12 | + .spender(fixture['data']['to'], int(fixture['data']['value'])) |
| 13 | + .to(fixture['data']['to']) |
| 14 | + .nonce(fixture['data']['nonce']) |
| 15 | + .gas_price(fixture['data']['gasPrice']) |
| 16 | + .gas_limit(fixture['data']['gasLimit']) |
| 17 | + .sign(passphrase) |
| 18 | + ) |
| 19 | + |
| 20 | + assert builder.transaction.data['gasPrice'] == int( |
| 21 | + fixture['data']['gasPrice'] |
| 22 | + ) |
| 23 | + assert builder.transaction.data['gasLimit'] == int( |
| 24 | + fixture['data']['gasLimit'] |
| 25 | + ) |
| 26 | + assert builder.transaction.data['nonce'] == fixture['data']['nonce'] |
| 27 | + assert builder.transaction.data['to'].lower() == ( |
| 28 | + fixture['data']['to'].lower() |
| 29 | + ) |
| 30 | + assert builder.transaction.data['v'] == fixture['data']['v'] |
| 31 | + assert builder.transaction.data['r'] == fixture['data']['r'] |
| 32 | + assert builder.transaction.data['s'] == fixture['data']['s'] |
| 33 | + assert builder.transaction.data['hash'] == fixture['data']['hash'] |
| 34 | + |
| 35 | + assert builder.verify() |
| 36 | + |
| 37 | + |
| 38 | +def test_token_approve_serialization(passphrase, load_transaction_fixture): |
| 39 | + fixture = load_transaction_fixture('transactions/token-approve') |
| 40 | + |
| 41 | + builder = ( |
| 42 | + TokenApproveBuilder |
| 43 | + .new() |
| 44 | + .spender(fixture['data']['to'], int(fixture['data']['value'])) |
| 45 | + .to(fixture['data']['to']) |
| 46 | + .nonce(fixture['data']['nonce']) |
| 47 | + .gas_price(fixture['data']['gasPrice']) |
| 48 | + .gas_limit(fixture['data']['gasLimit']) |
| 49 | + .sign(passphrase) |
| 50 | + ) |
| 51 | + |
| 52 | + serialized = builder.transaction.serialize().hex() |
| 53 | + assert serialized == fixture['serialized'] |
0 commit comments