Skip to content

Commit

Permalink
adding more tests (#22)
Browse files Browse the repository at this point in the history
* adding more tests

* fix event import

---------

Co-authored-by: Viacheslav Zhygulin <[email protected]>
  • Loading branch information
szhygulin and Viacheslav Zhygulin authored Jun 20, 2024
1 parent 7425822 commit ae8c7bc
Showing 1 changed file with 144 additions and 5 deletions.
149 changes: 144 additions & 5 deletions test/BTCDepositAddressDeriver.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import {Test} from "forge-std/Test.sol";
import {BTCDepositAddressDeriver} from "../src/BTCDepositAddressDeriver.sol";

contract BTCDepositAddressDeriverTest is Test {
// We declare event SeedChanged second time here because Solidity
// does not allow importing events from other contracts.
// https://ethereum.stackexchange.com/questions/52967/can-a-contract-emit-another-contracts-event
event SeedChanged(string btcAddr1, string btcAddr2, string hrp);

BTCDepositAddressDeriver deriver;

Expand Down Expand Up @@ -48,6 +44,149 @@ contract BTCDepositAddressDeriverTest is Test {
);
}

function testParseBTCTaprootAddress3() public {
vm.expectRevert();
(uint256 x, uint256 y) = deriver.parseBTCTaprootAddress(
"tb",
"tc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vq5zuyut"
);
}

function testParseBTCTaprootAddress4() public {
vm.expectRevert();
(uint256 x, uint256 y) = deriver.parseBTCTaprootAddress(
"bc",
"bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqh2y7hd"
);
}

function testParseBTCTaprootAddress5() public {
vm.expectRevert();
(uint256 x, uint256 y) = deriver.parseBTCTaprootAddress(
"bc",
"BC1S0XLXVLHEMJA6C4DQV22UAPCTQUPFHLXM9H8Z3K2E72Q4K9HCZ7VQ54WELL"
);
}

function testParseBTCTaprootAddress6() public {
vm.expectRevert();
(uint256 x, uint256 y) = deriver.parseBTCTaprootAddress(
"tb",
"tb1q0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vq24jc47"
);
}

function testParseBTCTaprootAddress7() public {
vm.expectRevert();
(uint256 x, uint256 y) = deriver.parseBTCTaprootAddress(
"bc",
"bc1p38j9r5y49hruaue7wxjce0updqjuyyx0kh56v8s25huc6995vvpql3jow4"
);
}

function testParseBTCTaprootAddress8() public {
vm.expectRevert();
(uint256 x, uint256 y) = deriver.parseBTCTaprootAddress(
"bc",
"BC130XLXVLHEMJA6C4DQV22UAPCTQUPFHLXM9H8Z3K2E72Q4K9HCZ7VQ7ZWS8R"
);
}

function testParseBTCTaprootAddress9() public {
vm.expectRevert();
(uint256 x, uint256 y) = deriver.parseBTCTaprootAddress(
"bc",
"bc1pw5dgrnzv"
);
}

function testParseBTCTaprootAddress10() public {
vm.expectRevert();
(uint256 x, uint256 y) = deriver.parseBTCTaprootAddress(
"bc",
"bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7v8n0nx0muaewav253zgeav"
);
}

function testParseBTCTaprootAddress11() public {
vm.expectRevert();
(uint256 x, uint256 y) = deriver.parseBTCTaprootAddress(
"tb",
"tb1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vq47Zagq"
);
}

function testParseBTCTaprootAddress12() public {
vm.expectRevert();
(uint256 x, uint256 y) = deriver.parseBTCTaprootAddress(
"bc",
"bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7v07qwwzcrf"
);
}

function testParseBTCTaprootAddress13() public {
vm.expectRevert();
(uint256 x, uint256 y) = deriver.parseBTCTaprootAddress(
"tb",
"tb1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vpggkg4j"
);
}

function testParseBTCTaprootAddress14() public {
vm.expectRevert();
(uint256 x, uint256 y) = deriver.parseBTCTaprootAddress(
"bc",
"bc1gmk9yu"
);
}

function testParseBTCTaprootAddress15() public {
(uint256 x, uint256 y) = deriver.parseBTCTaprootAddress(
"bc",
"bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqzk5jj0"
);
assertEq(
x,
0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798
);
assertEq(
y,
0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8
);
}

function testParseBTCTaprootAddress16() public {
(uint256 x, uint256 y) = deriver.parseBTCTaprootAddress(
"tb",
"tb1pqqqqp399et2xygdj5xreqhjjvcmzhxw4aywxecjdzew6hylgvsesf3hn0c"
);
assertEq(
x,
0xC4A5CAD46221B2A187905E5266362B99D5E91C6CE24D165DAB93E86433
);
assertEq(
y,
0xE938F4061E36DEF24C05DDCFD738363AAFF7BBC09267C7079451A0F169500766
);
}

function testParseBTCTaprootAddress17() public {
(uint256 x, uint256 y) = deriver.parseBTCTaprootAddress(
"bc",
"bc1pldma57nkrdrvtx7elspzgfa23qcxglzzunxxmqkwq8pnwpa4sd6s3406mu"
);
assertEq(
x,
0xFB77DA7A761B46C59BD9FC022427AA8830647C42E4CC6D82CE01C33707B58375
);
assertEq(
y,
0x68251ED41C7645E4AE49F68B0F4A207E4327501CB0B4BB7E3F5D86EF815794C6
);
//console.log("pubkey:", x, y);
}


function testSetSeed() public {
assertEq(deriver.wasSeedSet(), false);
assertEq(deriver.btcAddr1(), "");
Expand All @@ -59,7 +198,7 @@ contract BTCDepositAddressDeriverTest is Test {
assertEq(deriver.p2y(), 0);

vm.expectEmit(address(deriver));
emit SeedChanged(
emit BTCDepositAddressDeriver.SeedChanged(
"tb1p7g532zgvuzv8fz3hs02wvn2almqh8qyvz4xdr564nannkxh28kdq62ewy3",
"tb1psfpmk6v8cvd8kr4rdda0l8gwyn42v5yfjlqkhnureprgs5tuumkqvdkewz",
"tb"
Expand Down

0 comments on commit ae8c7bc

Please sign in to comment.