Skip to content

Commit

Permalink
Fix right pad hash check.
Browse files Browse the repository at this point in the history
  • Loading branch information
miohtama committed May 13, 2017
1 parent 02d9f16 commit 0fa6cc8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
21 changes: 21 additions & 0 deletions contracts/test/TestSolidityAddressHash.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@


/**
* Test address hash behavior with left and right padded zeroes.
*/
contract TestSolidityAddressHash {

address public leftPad = 0x00b5557397B157a17fb1AbCa97a38e4646BEDb88;
address public rightPad = 0x88b5557397B157a17fb1AbCa97a38e4646BEDb00;

function getHashLeftPad() public constant returns (bytes32) {
bytes32 hash = sha256(leftPad);
return hash;
}

function getHashRightPad() public constant returns (bytes32) {
bytes32 hash = sha256(rightPad);
return hash;
}

}
29 changes: 29 additions & 0 deletions ico/tests/contracts/test_require_signed_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import uuid

import binascii
import bitcoin
import pytest
from eth_utils import force_bytes
from ethereum.tester import TransactionFailed
from eth_utils import to_wei

Expand Down Expand Up @@ -45,6 +48,13 @@ def customer_id(uncapped_flatprice, uncapped_flatprice_finalizer, team_multisig)
return customer_id


@pytest.fixture
def pad_contract(chain):
"""Token contract we are buying."""
contract, hash = chain.provider.deploy_contract('TestSolidityAddressHash')
return contract


def test_only_owner_change_change_policy(crowdsale, customer, signer_address):
"""Only owner change change customerId required policy."""

Expand Down Expand Up @@ -90,3 +100,22 @@ def test_participate_bad_signature(chain, crowdsale, customer, customer_id, toke
with pytest.raises(TransactionFailed):
crowdsale.transact({"from": customer, "value": wei_value}).buyWithSignedAddress(customer_id, sign_data["v"], sign_data["r_bytes"], sign_data["s_bytes"])


def test_left_pad(pad_contract):
"""Ensure we handle leading zero in the address correctly."""

address_bytes = get_address_as_bytes(pad_contract.call().leftPad())
hash = bitcoin.bin_sha256(address_bytes)
val = pad_contract.call().getHashLeftPad()
val = force_bytes(val)
assert hash == val


def test_right_pad(pad_contract):
"""Ensure we handle trailing zero in the address correctly."""

address_bytes = get_address_as_bytes(pad_contract.call().rightPad())
hash = bitcoin.bin_sha256(address_bytes)
val = pad_contract.call().getHashRightPad()
val = force_bytes(val)
assert hash == val

0 comments on commit 0fa6cc8

Please sign in to comment.