Skip to content

Commit

Permalink
Migrated to hardhat
Browse files Browse the repository at this point in the history
  • Loading branch information
Arachnid committed Apr 14, 2021
1 parent 6210d11 commit 1a37812
Show file tree
Hide file tree
Showing 9 changed files with 8,249 additions and 3,863 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
build/
node_modules/
.env
cache
artifacts
15 changes: 15 additions & 0 deletions hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require("@nomiclabs/hardhat-truffle5");

module.exports = {
networks: {
hardhat: {
// Required for real DNS record tests
initialDate: "2019-03-15T14:06:45.000+13:00"
}
},
mocha: {
},
solidity: {
version: "0.7.4",
},
};
11,792 changes: 8,041 additions & 3,751 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@
"devDependencies": {
"@ensdomains/buffer": "^0.0.8",
"@ensdomains/solsha1": "^0.0.2",
"@nomiclabs/hardhat-truffle5": "^2.0.0",
"@nomiclabs/hardhat-web3": "^2.0.0",
"@truffle/hdwallet-provider": "^1.2.1",
"dnsprovejs": "0.0.9",
"dotenv": "^8.2.0",
"elliptic-solidity": "1.0.0",
"eth-gas-reporter": "^0.1.12",
"hardhat": "^2.1.2",
"rfc4648": "^1.1.0",
"solium": "^1.2.3",
"truffle": "^5.1.53",
"truffle-plugin-verify": "^0.5.4"
"truffle-plugin-verify": "^0.5.4",
"web3": "^1.3.5"
},
"scripts": {
"pretest": "truffle compile",
Expand Down
101 changes: 50 additions & 51 deletions test/TestBytesUtils.sol
Original file line number Diff line number Diff line change
@@ -1,83 +1,82 @@
pragma solidity ^0.7.4;

import "truffle/Assert.sol";
import "../contracts/RRUtils.sol";
import "../contracts/BytesUtils.sol";

contract TestBytesUtils {
using BytesUtils for *;

function testKeccak() public {
Assert.equal("".keccak(0, 0), bytes32(0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470), "Incorrect hash of empty string");
Assert.equal("foo".keccak(0, 3), bytes32(0x41b1a0649752af1b28b3dc29a1556eee781e4a4c3a1f7f53f90fa834de098c4d), "Incorrect hash of 'foo'");
Assert.equal("foo".keccak(0, 0), bytes32(0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470), "Incorrect hash of empty string");
function testKeccak() public pure {
require("".keccak(0, 0) == bytes32(0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470), "Incorrect hash of empty string");
require("foo".keccak(0, 3) == bytes32(0x41b1a0649752af1b28b3dc29a1556eee781e4a4c3a1f7f53f90fa834de098c4d), "Incorrect hash of 'foo'");
require("foo".keccak(0, 0) == bytes32(0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470), "Incorrect hash of empty string");
}

function testEquals() public {
Assert.equal("hello".equals("hello"), true, "String equality");
Assert.equal("hello".equals("goodbye"), false, "String inequality");
Assert.equal("hello".equals(1, "ello"), true, "Substring to string equality");
Assert.equal("hello".equals(1, "jello", 1, 4), true, "Substring to substring equality");
Assert.equal("zhello".equals(1, "abchello", 3), true, "Compare different value with multiple length");
function testEquals() public pure {
require("hello".equals("hello") == true, "String equality");
require("hello".equals("goodbye") == false, "String inequality");
require("hello".equals(1, "ello") == true, "Substring to string equality");
require("hello".equals(1, "jello", 1, 4) == true, "Substring to substring equality");
require("zhello".equals(1, "abchello", 3) == true, "Compare different value with multiple length");
}

function testComparePartial() public {
Assert.equal("xax".compare(1, 1, "xxbxx", 2, 1) < 0, true, "Compare same length");
Assert.equal("xax".compare(1, 1, "xxabxx", 2, 2) < 0, true, "Compare different length");
Assert.equal("xax".compare(1, 1, "xxaxx", 2, 1) == 0, true, "Compare same with different offset");
function testComparePartial() public pure {
require("xax".compare(1, 1, "xxbxx", 2, 1) < 0 == true, "Compare same length");
require("xax".compare(1, 1, "xxabxx", 2, 2) < 0 == true, "Compare different length");
require("xax".compare(1, 1, "xxaxx", 2, 1) == 0 == true, "Compare same with different offset");
}

function testCompare() public {
Assert.equal("a".compare("a") == 0, true, "Compare equal");
Assert.equal("a".compare("b") < 0, true, "Compare different value with same length");
Assert.equal("b".compare("a") > 0, true, "Compare different value with same length");
Assert.equal("aa".compare("ab") < 0, true, "Compare different value with multiple length");
Assert.equal("a".compare("aa") < 0, true, "Compare different value with different length");
Assert.equal("aa".compare("a") > 0, true, "Compare different value with different length");
function testCompare() public pure {
require("a".compare("a") == 0 == true, "Compare equal");
require("a".compare("b") < 0 == true, "Compare different value with same length");
require("b".compare("a") > 0 == true, "Compare different value with same length");
require("aa".compare("ab") < 0 == true, "Compare different value with multiple length");
require("a".compare("aa") < 0 == true, "Compare different value with different length");
require("aa".compare("a") > 0 == true, "Compare different value with different length");
bytes memory longChar = "1234567890123456789012345678901234";
Assert.equal(longChar.compare(longChar) == 0, true, "Compares more than 32 bytes char");
require(longChar.compare(longChar) == 0 == true, "Compares more than 32 bytes char");
bytes memory otherLongChar = "2234567890123456789012345678901234";
Assert.equal(longChar.compare(otherLongChar) < 0, true, "Compare long char with difference at start");
require(longChar.compare(otherLongChar) < 0 == true, "Compare long char with difference at start");
}

function testSubstring() public {
Assert.equal(string("hello".substring(0, 0)), "", "Copy 0 bytes");
Assert.equal(string("hello".substring(0, 4)), "hell", "Copy substring");
Assert.equal(string("hello".substring(1, 4)), "ello", "Copy substring");
Assert.equal(string("hello".substring(0, 5)), "hello", "Copy whole string");
function testSubstring() public pure {
require(keccak256(bytes("hello".substring(0, 0))) == keccak256(bytes("")), "Copy 0 bytes");
require(keccak256(bytes("hello".substring(0, 4))) == keccak256(bytes("hell")), "Copy substring");
require(keccak256(bytes("hello".substring(1, 4))) == keccak256(bytes("ello")), "Copy substring");
require(keccak256(bytes("hello".substring(0, 5))) == keccak256(bytes("hello")), "Copy whole string");
}

function testReadUint8() public {
Assert.equal(uint("a".readUint8(0)), 0x61, "a == 0x61");
Assert.equal(uint("ba".readUint8(1)), 0x61, "a == 0x61");
function testReadUint8() public pure {
require(uint("a".readUint8(0)) == 0x61, "a == 0x61");
require(uint("ba".readUint8(1)) == 0x61, "a == 0x61");
}

function testReadUint16() public {
Assert.equal(uint("abc".readUint16(1)), 0x6263, "Read uint 16");
function testReadUint16() public pure {
require(uint("abc".readUint16(1)) == 0x6263, "Read uint 16");
}

function testReadUint32() public {
Assert.equal(uint("abcde".readUint32(1)), 0x62636465, "Read uint 32");
function testReadUint32() public pure {
require(uint("abcde".readUint32(1)) == 0x62636465, "Read uint 32");
}

function testReadBytes20() public {
Assert.equal(bytes32("abcdefghijklmnopqrstuv".readBytes20(1)), bytes32(0x62636465666768696a6b6c6d6e6f707172737475000000000000000000000000), "readBytes20");
function testReadBytes20() public pure {
require(bytes32("abcdefghijklmnopqrstuv".readBytes20(1)) == bytes32(0x62636465666768696a6b6c6d6e6f707172737475000000000000000000000000), "readBytes20");
}

function testReadBytes32() public {
Assert.equal("0123456789abcdef0123456789abcdef".readBytes32(0), bytes32(0x3031323334353637383961626364656630313233343536373839616263646566), "readBytes32");
function testReadBytes32() public pure {
require("0123456789abcdef0123456789abcdef".readBytes32(0) == bytes32(0x3031323334353637383961626364656630313233343536373839616263646566), "readBytes32");
}

function testBase32HexDecodeWord() public {
Assert.equal("C4".base32HexDecodeWord(0, 2), bytes32(bytes1("a")), "Decode 'a'");
Assert.equal("C5GG".base32HexDecodeWord(0, 4), bytes32(bytes2("aa")), "Decode 'aa'");
Assert.equal("C5GM2".base32HexDecodeWord(0, 5), bytes32(bytes3("aaa")), "Decode 'aaa'");
Assert.equal("C5GM2O8".base32HexDecodeWord(0, 7), bytes32(bytes4("aaaa")), "Decode 'aaaa'");
Assert.equal("C5GM2OB1".base32HexDecodeWord(0, 8), bytes32(bytes5("aaaaa")), "Decode 'aaaaa'");
Assert.equal("c5gm2Ob1".base32HexDecodeWord(0, 8), bytes32(bytes5("aaaaa")), "Decode 'aaaaa' lowercase");
Assert.equal("C5H66P35CPJMGQBADDM6QRJFE1ON4SRKELR7EU3PF8".base32HexDecodeWord(0, 42), bytes32(bytes26("abcdefghijklmnopqrstuvwxyz")), "Decode alphabet");
Assert.equal("c5h66p35cpjmgqbaddm6qrjfe1on4srkelr7eu3pf8".base32HexDecodeWord(0, 42), bytes32(bytes26("abcdefghijklmnopqrstuvwxyz")), "Decode alphabet lowercase");
Assert.equal("C5GM2OB1C5GM2OB1C5GM2OB1C5GM2OB1C5GM2OB1C5GM2OB1C5GG".base32HexDecodeWord(0, 52), bytes32("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), "Decode 32*'a'");
Assert.equal(" bst4hlje7r0o8c8p4o8q582lm0ejmiqt\x07matoken\x03xyz\x00".base32HexDecodeWord(1, 32), bytes32(hex"5f3a48d66e3ec18431192611a2a055b01d3b4b5d"), "Decode real bytes32hex");
function testBase32HexDecodeWord() public pure {
require("C4".base32HexDecodeWord(0, 2) == bytes32(bytes1("a")), "Decode 'a'");
require("C5GG".base32HexDecodeWord(0, 4) == bytes32(bytes2("aa")), "Decode 'aa'");
require("C5GM2".base32HexDecodeWord(0, 5) == bytes32(bytes3("aaa")), "Decode 'aaa'");
require("C5GM2O8".base32HexDecodeWord(0, 7) == bytes32(bytes4("aaaa")), "Decode 'aaaa'");
require("C5GM2OB1".base32HexDecodeWord(0, 8) == bytes32(bytes5("aaaaa")), "Decode 'aaaaa'");
require("c5gm2Ob1".base32HexDecodeWord(0, 8) == bytes32(bytes5("aaaaa")), "Decode 'aaaaa' lowercase");
require("C5H66P35CPJMGQBADDM6QRJFE1ON4SRKELR7EU3PF8".base32HexDecodeWord(0, 42) == bytes32(bytes26("abcdefghijklmnopqrstuvwxyz")), "Decode alphabet");
require("c5h66p35cpjmgqbaddm6qrjfe1on4srkelr7eu3pf8".base32HexDecodeWord(0, 42) == bytes32(bytes26("abcdefghijklmnopqrstuvwxyz")), "Decode alphabet lowercase");
require("C5GM2OB1C5GM2OB1C5GM2OB1C5GM2OB1C5GM2OB1C5GM2OB1C5GG".base32HexDecodeWord(0, 52) == bytes32("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), "Decode 32*'a'");
require(" bst4hlje7r0o8c8p4o8q582lm0ejmiqt\x07matoken\x03xyz\x00".base32HexDecodeWord(1, 32) == bytes32(hex"5f3a48d66e3ec18431192611a2a055b01d3b4b5d"), "Decode real bytes32hex");
}
}
40 changes: 19 additions & 21 deletions test/TestDNSSEC.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ async function verifyFailedSubmission(instance, data, sig, proof) {
// Assert ganache revert exception
assert.equal(
error.message,
'Returned error: VM Exception while processing transaction: revert'
'Transaction reverted without a reason'
);
}

Expand All @@ -109,8 +109,26 @@ async function verifyFailedSubmission(instance, data, sig, proof) {
}
}

// Test against real record
contract('DNSSEC', accounts => {
it('should accept real DNSSEC records', async function() {
var instance = await dnssec.deployed();
var proof = await instance.anchors();
for (let i = 0; i < test_rrsets.length; i++) {
var rrset = test_rrsets[i];
var tx = await instance.submitRRSet([rrset[1], rrset[2]], proof);
proof = tx.logs[0].args.rrset;
assert.equal(tx.receipt.status, true);
}
});
});

contract('DNSSEC', function(accounts) {
before(async () => {
// Advance to the current time so the DNSSEC root keys work.
await network.provider.send("evm_setNextBlockTimestamp", [Date.now() / 1000]);
await network.provider.send("evm_mine");

const instance = await dnssec.deployed();
const keys = rootKeys();
const [signedData] = hexEncodeSignedSet(keys);
Expand Down Expand Up @@ -1331,23 +1349,3 @@ contract('DNSSEC', function(accounts) {
assert.equal(await checkPresence(instance, 'TXT', 'foo.matoken.xyz'), true);
});
});

// Test against real record
contract('DNSSEC', accounts => {
it('should accept real DNSSEC records', async function() {
var instance = await dnssec.deployed();
var proof = await instance.anchors();
// They were all valid at Fri Mar 15 14:06:45 2019 +1300 and
// will be again every 2^32 seconds or 136 years
await web3.currentProvider.send({
method: 'evm_increaseTime',
params: (1552612005 - Date.now() / 1000) >>> 0
});
for (let i = 0; i < test_rrsets.length; i++) {
var rrset = test_rrsets[i];
var tx = await instance.submitRRSet([rrset[1], rrset[2]], proof);
proof = tx.logs[0].args.rrset;
assert.equal(tx.receipt.status, true);
}
});
});
Loading

0 comments on commit 1a37812

Please sign in to comment.