tests: added more testing
This commit is contained in:
parent
8bece98e3e
commit
55a6c9b715
@ -39,10 +39,10 @@ function writeVersion(version: string): void {
|
||||
const remotePkgInfo = remoteInfo.versions[remoteVersion];
|
||||
const remoteGitHead = remotePkgInfo.gitHead;
|
||||
|
||||
//const gitHead = await getGitTag(resolve("."));
|
||||
let gitHead = "";
|
||||
for (const log of await getGitLog(".")) {
|
||||
if (log.body.startsWith("admin:")) { continue; }
|
||||
if (log.body.startsWith("tests:")) { continue; }
|
||||
gitHead = log.commit;
|
||||
break;
|
||||
}
|
||||
|
@ -3,7 +3,10 @@ import { loadTests } from "./utils.js";
|
||||
|
||||
import { TestCaseAbi, TestCaseAbiVerbose } from "./types.js";
|
||||
|
||||
import { defaultAbiCoder } from "../index.js";
|
||||
import {
|
||||
defaultAbiCoder, Interface,
|
||||
decodeBytes32String, encodeBytes32String
|
||||
} from "../index.js";
|
||||
|
||||
function equal(actual: any, expected: TestCaseAbiVerbose): void {
|
||||
switch (expected.type) {
|
||||
@ -41,3 +44,80 @@ describe("Tests ABI Coder", function() {
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe("Test Bytes32 strings", function() {
|
||||
it("encodes and decodes Bytes32 strings @TODO: exapnd", function() {
|
||||
const str = "ricmoo.firefly.eth";
|
||||
const bytes32 = encodeBytes32String(str);
|
||||
const str2 = decodeBytes32String(bytes32);
|
||||
assert.equal(bytes32, '0x7269636d6f6f2e66697265666c792e6574680000000000000000000000000000', 'formatted correctly');
|
||||
assert.equal(str2, str, "parsed correctly");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Test Interface", function() {
|
||||
const iface = new Interface([
|
||||
"function balanceOf(address owner) returns (uint)",
|
||||
"event Transfer(address indexed from, address indexed to, uint amount)"
|
||||
]);
|
||||
|
||||
it("does interface stuff; @TODO expand this", function() {
|
||||
const addr = "0x8ba1f109551bD432803012645Ac136ddd64DBA72";
|
||||
const addr2 = "0xAC1639CF97a3A46D431e6d1216f576622894cBB5";
|
||||
|
||||
const data = iface.encodeFunctionData("balanceOf", [ addr ]);
|
||||
assert.equal(data, "0x70a082310000000000000000000000008ba1f109551bd432803012645ac136ddd64dba72", "encoded");
|
||||
|
||||
const decoded = iface.decodeFunctionData("balanceOf", data);
|
||||
assert.equal(decoded.length, 1, "decoded.length");
|
||||
assert.equal(decoded[0], addr, "decoded[0]");
|
||||
|
||||
const tx = iface.parseTransaction({ data, value: 10 });
|
||||
assert.ok(tx != null, "tx == null");
|
||||
assert.equal(tx.name, "balanceOf", "tx.balanceOf");
|
||||
assert.equal(tx.signature, "balanceOf(address)", "tx.balanceOf");
|
||||
assert.equal(tx.args.length, 1, "tx.args.length");
|
||||
assert.equal(tx.args[0], addr, "tx.args[0]");
|
||||
assert.equal(tx.selector, "0x70a08231", "tx.selector");
|
||||
assert.equal(tx.value, BigInt(10), "tx.value");
|
||||
|
||||
const result = iface.encodeFunctionResult("balanceOf", [ 123 ]);
|
||||
assert.equal(result, "0x000000000000000000000000000000000000000000000000000000000000007b", "result");
|
||||
|
||||
const value = iface.decodeFunctionResult("balanceOf", result);
|
||||
assert.equal(value.length, 1, "result.length");
|
||||
assert.equal(value[0], BigInt(123), "result.value[0]");
|
||||
|
||||
// @TODO: parseResult
|
||||
|
||||
const filter = iface.encodeFilterTopics("Transfer", [ addr, addr2 ]);
|
||||
assert.equal(filter.length, 3);
|
||||
assert.equal(filter[0], "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef");
|
||||
assert.equal(filter[1], "0x0000000000000000000000008ba1f109551bd432803012645ac136ddd64dba72");
|
||||
assert.equal(filter[2], "0x000000000000000000000000ac1639cf97a3a46d431e6d1216f576622894cbb5");
|
||||
|
||||
const eventLog = iface.encodeEventLog("Transfer", [ addr, addr2, 234 ]);
|
||||
assert.equal(eventLog.data, "0x00000000000000000000000000000000000000000000000000000000000000ea");
|
||||
assert.deepEqual(eventLog.topics, [
|
||||
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
|
||||
"0x0000000000000000000000008ba1f109551bd432803012645ac136ddd64dba72",
|
||||
"0x000000000000000000000000ac1639cf97a3a46d431e6d1216f576622894cbb5"
|
||||
]);
|
||||
|
||||
const values = iface.decodeEventLog("Transfer", eventLog.data, eventLog.topics);
|
||||
assert.equal(values.length, 3);
|
||||
assert.equal(values[0], addr);
|
||||
assert.equal(values[1], addr2);
|
||||
assert.equal(values[2], BigInt(234));
|
||||
|
||||
const log = iface.parseLog(eventLog);
|
||||
assert.ok(log != null);
|
||||
assert.equal(log.name, "Transfer");
|
||||
assert.equal(log.signature, "Transfer(address,address,uint256)");
|
||||
assert.equal(log.topic, "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef");
|
||||
assert.equal(log.args.length, 3);
|
||||
assert.equal(log.args[0], "0x8ba1f109551bD432803012645Ac136ddd64DBA72");
|
||||
assert.equal(log.args[1], "0xAC1639CF97a3A46D431e6d1216f576622894cBB5");
|
||||
assert.equal(log.args[2], BigInt(234));
|
||||
});
|
||||
});
|
||||
|
@ -1,3 +1,22 @@
|
||||
import assert from "assert";
|
||||
|
||||
import { connect } from "./create-provider.js";
|
||||
|
||||
import { Contract } from "../index.js";
|
||||
|
||||
|
||||
describe("Test Contract", function() {
|
||||
it("tests contract @TODO: expand", async function() {
|
||||
const provider = connect("mainnet");
|
||||
|
||||
const contract = new Contract("dai.tokens.ethers.eth", [
|
||||
"function balanceOf(address) view returns (uint)"
|
||||
], provider);
|
||||
|
||||
assert.equal(await contract.balanceOf("ricmoo.firefly.eth"), BigInt("6015089439794538201631"));
|
||||
});
|
||||
});
|
||||
|
||||
/*
|
||||
import { Typed } from "../abi/index.js";
|
||||
import * as providers from "../providers/index.js";
|
||||
|
15
src.ts/_tests/test-providers-extra.ts
Normal file
15
src.ts/_tests/test-providers-extra.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import assert from "assert";
|
||||
|
||||
import { EtherscanProvider } from "../index.js";
|
||||
|
||||
import { retryIt } from "./utils.js";
|
||||
|
||||
|
||||
describe("Test Etherscan extra APIs", function() {
|
||||
retryIt("test etherscanProvider.getContract", async function() {
|
||||
const provider = new EtherscanProvider("mainnet", "FPFGK6JSW2UHJJ2666FG93KP7WC999MNW7");
|
||||
const contract = await provider.getContract("dai.tokens.ethers.eth");
|
||||
assert.ok(contract != null, "contract == null");
|
||||
assert.equal(await contract.symbol(), "DAI", "contract.symbol");
|
||||
});
|
||||
});
|
@ -1 +1 @@
|
||||
export const version = "6.0.0-beta-exports.3";
|
||||
export const version = "6.0.0-beta-exports.4";
|
||||
|
Loading…
Reference in New Issue
Block a user