|
1 | | -from crypto.enums.contract_addresses import ContractAddresses |
2 | | -from crypto.identity.proof_of_possession import ProofOfPossession |
3 | 1 | from crypto.transactions.builder.validator_update_builder import ValidatorUpdateBuilder |
4 | 2 |
|
5 | 3 |
|
6 | | -def test_validator_update_derives_bls_keys(passphrase, validator_passphrase): |
7 | | - builder = ( |
8 | | - ValidatorUpdateBuilder |
9 | | - .new() |
10 | | - .gas_price(5000000000) |
11 | | - .gas_limit(200000) |
12 | | - .nonce('1') |
13 | | - .validator_passphrase(validator_passphrase) |
14 | | - .sign(passphrase) |
15 | | - ) |
16 | | - |
17 | | - bls = ProofOfPossession.from_passphrase(validator_passphrase) |
18 | | - |
19 | | - assert builder.transaction.data['validatorPublicKey'] == '0x' + bls['pk'] |
20 | | - assert builder.transaction.data['validatorProof'] == '0x' + bls['pop'] |
21 | | - assert len(builder.transaction.data['validatorPublicKey']) == 98 # 0x + 96 hex = 48 bytes |
22 | | - assert len(builder.transaction.data['validatorProof']) == 194 # 0x + 192 hex = 96 bytes |
23 | | - |
| 4 | +def test_validator_update_transaction(passphrase, load_transaction_fixture): |
| 5 | + fixture = load_transaction_fixture('transactions/validator-update') |
24 | 6 |
|
25 | | -def test_validator_update_targets_consensus_contract(passphrase, validator_passphrase): |
26 | 7 | builder = ( |
27 | 8 | ValidatorUpdateBuilder |
28 | 9 | .new() |
29 | | - .validator_passphrase(validator_passphrase) |
| 10 | + .gas_price(fixture['data']['gasPrice']) |
| 11 | + .gas_limit(fixture['data']['gasLimit']) |
| 12 | + .nonce(fixture['data']['nonce']) |
| 13 | + .validator_passphrase(fixture['validatorPassphrase']) |
| 14 | + .to(fixture['data']['to']) |
30 | 15 | .sign(passphrase) |
31 | 16 | ) |
32 | 17 |
|
33 | | - assert builder.transaction.data['to'].lower() == ContractAddresses.CONSENSUS.value.lower() |
34 | | - |
35 | | - |
36 | | -def test_validator_update_value_is_zero(passphrase, validator_passphrase): |
37 | | - builder = ( |
38 | | - ValidatorUpdateBuilder |
39 | | - .new() |
40 | | - .validator_passphrase(validator_passphrase) |
41 | | - .sign(passphrase) |
42 | | - ) |
| 18 | + assert builder.transaction.data['gasPrice'] == int(fixture['data']['gasPrice']) |
| 19 | + assert builder.transaction.data['gasLimit'] == int(fixture['data']['gasLimit']) |
| 20 | + assert builder.transaction.data['nonce'] == fixture['data']['nonce'] |
| 21 | + assert builder.transaction.data['to'] == fixture['data']['to'] |
| 22 | + assert builder.transaction.data['value'] == int(fixture['data']['value']) |
| 23 | + assert builder.transaction.data['validatorPublicKey'] == fixture['data']['validatorPublicKey'] |
| 24 | + assert builder.transaction.data['validatorProof'] == fixture['data']['validatorProof'] |
| 25 | + assert builder.transaction.data['v'] == fixture['data']['v'] |
| 26 | + assert builder.transaction.data['r'] == fixture['data']['r'] |
| 27 | + assert builder.transaction.data['s'] == fixture['data']['s'] |
| 28 | + assert builder.transaction.data['hash'] == fixture['data']['hash'] |
| 29 | + assert builder.transaction.serialize().hex() == fixture['serialized'] |
| 30 | + assert builder.verify() |
43 | 31 |
|
44 | | - assert builder.transaction.data['value'] == 0 |
45 | 32 |
|
| 33 | +def test_validator_update_transaction_with_default_to(passphrase, load_transaction_fixture): |
| 34 | + fixture = load_transaction_fixture('transactions/validator-update') |
46 | 35 |
|
47 | | -def test_validator_update_verifies(passphrase, validator_passphrase): |
48 | 36 | builder = ( |
49 | 37 | ValidatorUpdateBuilder |
50 | 38 | .new() |
51 | | - .validator_passphrase(validator_passphrase) |
| 39 | + .gas_price(fixture['data']['gasPrice']) |
| 40 | + .gas_limit(fixture['data']['gasLimit']) |
| 41 | + .nonce(fixture['data']['nonce']) |
| 42 | + .validator_passphrase(fixture['validatorPassphrase']) |
52 | 43 | .sign(passphrase) |
53 | 44 | ) |
54 | 45 |
|
| 46 | + assert builder.transaction.data['gasPrice'] == int(fixture['data']['gasPrice']) |
| 47 | + assert builder.transaction.data['gasLimit'] == int(fixture['data']['gasLimit']) |
| 48 | + assert builder.transaction.data['nonce'] == fixture['data']['nonce'] |
| 49 | + assert builder.transaction.data['to'].lower() == fixture['data']['to'].lower() |
| 50 | + assert builder.transaction.data['value'] == int(fixture['data']['value']) |
| 51 | + assert builder.transaction.data['validatorPublicKey'] == fixture['data']['validatorPublicKey'] |
| 52 | + assert builder.transaction.data['validatorProof'] == fixture['data']['validatorProof'] |
| 53 | + assert builder.transaction.data['v'] == fixture['data']['v'] |
| 54 | + assert builder.transaction.data['r'] == fixture['data']['r'] |
| 55 | + assert builder.transaction.data['s'] == fixture['data']['s'] |
| 56 | + assert builder.transaction.data['hash'] == fixture['data']['hash'] |
| 57 | + assert builder.transaction.serialize().hex() == fixture['serialized'] |
55 | 58 | assert builder.verify() |
0 commit comments