Skip to content

Commit

Permalink
Implement getNonce/getVersionNo + Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sashafrolov committed Nov 22, 2017
1 parent 02ab1da commit c3198c1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
16 changes: 16 additions & 0 deletions contracts/BTCRelay.sol
Expand Up @@ -87,4 +87,20 @@ contract BTCRelay {
return tmp >> 224;
}

function getVersionNo(bytes header) public constant returns (uint){
uint tmp;
assembly {
tmp := mload(add(header,32))
}
return tmp >> 224;
}

function getNonce(bytes header) public constant returns(uint){
uint tmp;
assembly{
tmp := mload(add(header, 108))
}
return tmp >> 224;
}

}
14 changes: 14 additions & 0 deletions test/TestBTCRelay.sol
Expand Up @@ -89,4 +89,18 @@ contract TestBTCRelay {
uint res = relay.getTimestamp(header);
Assert.equal(res, 0xabcdef12, "getTimestamp");
}

function testGetVersionNo(){
BTCRelay relay = BTCRelay(DeployedAddresses.BTCRelay());
bytes memory header = hex"f01dab1e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f01dab1e";
uint version = relay.getVersionNo(header);
Assert.equal(version, 0xf01dab1e, "getVersionNo");
}

function testGetNonce(){
BTCRelay relay = BTCRelay(DeployedAddresses.BTCRelay());
bytes memory header = hex"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c105e7edc105e7ed";
uint nonce = relay.getNonce(header);
Assert.equal(nonce, 0xc105e7ed, "getNonce");
}
}

0 comments on commit c3198c1

Please sign in to comment.