mirror of
https://github.com/AthanorLabs/atomic-swap.git
synced 2026-01-10 06:38:04 -05:00
cleanup ethereum tests (#77)
This commit is contained in:
@@ -1,40 +0,0 @@
|
||||
// SPDX-License-Identifier: LGPLv3
|
||||
|
||||
pragma solidity ^0.8.5;
|
||||
|
||||
import "./Swap.sol";
|
||||
import "./TestUtils.sol";
|
||||
|
||||
contract SwapMock is Swap, TestUtils {
|
||||
uint256 constant gx =
|
||||
0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798;
|
||||
uint256 constant gy =
|
||||
0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8;
|
||||
uint256 constant n =
|
||||
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F;
|
||||
uint256 constant a = 0;
|
||||
uint256 constant b = 7;
|
||||
|
||||
uint256 constant m =
|
||||
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141;
|
||||
|
||||
address payable mockAddress = payable(0);
|
||||
|
||||
constructor() Swap(0, 0, mockAddress, 60) {}
|
||||
|
||||
function testVerifySecret(uint256 s, bytes32 ctment) view external {
|
||||
address signer = ecrecover(
|
||||
0,
|
||||
gy % 2 != 0 ? 28 : 27,
|
||||
bytes32(gx),
|
||||
bytes32(mulmod(s, gx, m))
|
||||
);
|
||||
|
||||
// console.log("ctment: %s", uint2hexstr(uint256(ctment)));
|
||||
// console.log("addr: %s", address(uint160(uint256(ctment))));
|
||||
// console.log("s: %s", s);
|
||||
console.log("derived: %s", signer);
|
||||
|
||||
require(address(uint160(uint256(ctment))) == signer);
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ pragma solidity ^0.8.5;
|
||||
import "hardhat/console.sol";
|
||||
|
||||
contract TestUtils {
|
||||
|
||||
function uint2hexstr(uint256 i) public pure returns (string memory) {
|
||||
if (i == 0) return "0";
|
||||
uint256 j = i;
|
||||
|
||||
@@ -9,7 +9,7 @@ function KeyPair(s, pubKey_x, pubKey_y) {
|
||||
this.pubKey_y = pubKey_y;
|
||||
}
|
||||
|
||||
describe("Swap", function () {
|
||||
describe("Secp256k1", function () {
|
||||
const test_vecs = [
|
||||
new KeyPair('0xD30519BCAE8D180DBFCC94FE0B8383DC310185B0BE97B4365083EBCECCD75759',
|
||||
'0x3AF1E1EFA4D1E1AD5CB9E3967E98E901DAFCD37C44CF0BFB6C216997F5EE51DF',
|
||||
@@ -21,23 +21,20 @@ describe("Swap", function () {
|
||||
|
||||
let swap;
|
||||
beforeEach(async function () {
|
||||
const Swap = await ethers.getContractFactory("SwapMock");
|
||||
swap = await Swap.deploy();
|
||||
const Secp256k1 = await ethers.getContractFactory("Secp256k1");
|
||||
secp256k1 = await Secp256k1.deploy();
|
||||
});
|
||||
|
||||
it("Should verify commitment correctly with test vecs", async function () {
|
||||
let promises = [];
|
||||
test_vecs.forEach(async function (kp, i) {
|
||||
const qKeccak = ethers.utils.solidityKeccak256(
|
||||
["uint256", "uint256"],
|
||||
[kp.pubKey_x, kp.pubKey_y]);
|
||||
|
||||
console.log(qKeccak)
|
||||
|
||||
console.log('Testing %s of %s test vectors...', i + 1, test_vecs.length);
|
||||
promises.push(swap.testVerifySecret(arrayify(kp.s), arrayify(qKeccak)));
|
||||
let ok = await secp256k1.mulVerify(arrayify(kp.s), arrayify(qKeccak));
|
||||
expect(ok).to.equal(true);
|
||||
});
|
||||
await Promise.all(promises);
|
||||
});
|
||||
|
||||
// TODO: write test with randomly generated secrets
|
||||
|
||||
Reference in New Issue
Block a user