Skip to content

Commit

Permalink
tests: add testWithAnvil
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasbrugneaux committed Aug 21, 2024
1 parent e4a4bab commit 070a5a1
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 25 deletions.
Binary file modified bun.lockb
Binary file not shown.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
"web3": ">= 4.0.2 < 5"
},
"devDependencies": {
"@celo/dev-utils": "^0.0.5",
"@celo/devchain-anvil": "12.0.0-canary.0",
"@celo/typescript": "^0.0.2",
"@types/bun": "^1.1.6",
"eslint": "^9.8.0",
Expand All @@ -37,5 +39,8 @@
"@celo/abis-l2": "npm:@celo/abis@12.0.0-canary.23",
"web3-eth-accounts": "^4.1.3",
"web3-utils": "^4.3.1"
},
"patchedDependencies": {
"@celo/dev-utils@0.0.5": "patches/@celo+dev-utils@0.0.5.patch"
}
}
50 changes: 50 additions & 0 deletions patches/@celo+dev-utils@0.0.5.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
diff --git a/lib/anvil-test.js b/lib/anvil-test.js
index 94009386b44285a560e08a95d870ec27995f2360..64197a2cb0b765e80c4b554c53a08c555981e08d 100644
--- a/lib/anvil-test.js
+++ b/lib/anvil-test.js
@@ -10,7 +10,8 @@ exports.STABLES_ADDRESS = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266';
exports.DEFAULT_OWNER_ADDRESS = exports.STABLES_ADDRESS;
function createInstance(stateFilePath) {
// preparation for not needing to have --runInBand for anvil tests
- const port = ANVIL_PORT + (process.pid - process.ppid);
+ let port = ANVIL_PORT + (process.pid - process.ppid);
+ port += Math.floor(Math.random() * 1000)
const options = {
port,
loadState: stateFilePath,
diff --git a/lib/test-utils.js b/lib/test-utils.js
index 3fb8780db1d7fcf1b97edd4db558976853326354..28115e121c56a17d86d73a7573e54c69997d628e 100644
--- a/lib/test-utils.js
+++ b/lib/test-utils.js
@@ -4,6 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.testWithWeb3 = exports.evmSnapshot = exports.evmRevert = exports.jsonRpcCall = exports.NetworkConfig = exports.TEST_GAS_LIMIT = exports.TEST_GAS_PRICE = exports.TEST_BALANCE = exports.TEST_MNEMONIC = void 0;
+
+const { beforeAll, beforeEach, describe, afterAll } = require('bun:test')
+
const web3_1 = __importDefault(require("web3"));
const migration_override_json_1 = __importDefault(require("./migration-override.json"));
exports.TEST_MNEMONIC = 'concert load couple harbor equip island argue ramp clarify fence smart topic';
diff --git a/package.json b/package.json
index 54ce3ea580a0259264c487522ec6c471bd82fd2a..278a0278418b09948b5631be9cb32b72aed7a2fd 100644
--- a/package.json
+++ b/package.json
@@ -28,7 +28,6 @@
"ganache": "npm:@celo/ganache@7.8.0-unofficial.0",
"targz": "^1.0.1",
"tmp": "^0.1.0",
- "web3": "1.10.4",
"web3-core-helpers": "1.10.4"
},
"devDependencies": {
@@ -38,6 +37,9 @@
"@types/fs-extra": "^8.1.0",
"@types/targz": "1.0.0"
},
+ "peerDependencies": {
+ "web3": "*"
+ },
"engines": {
"node": ">=18.14.2"
}
6 changes: 0 additions & 6 deletions src/cip64.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,6 @@ export class CIP64Transaction extends BaseTransaction<CIP64Transaction> {

public serialize(): Uint8Array {
const base = this.raw();
console.log({
base,
TRANSACTION_TYPE_UINT8ARRAY,
encoded: RLP.encode(base),
full: uint8ArrayConcat(TRANSACTION_TYPE_UINT8ARRAY, RLP.encode(base)),
});
return uint8ArrayConcat(TRANSACTION_TYPE_UINT8ARRAY, RLP.encode(base));
}

Expand Down
4 changes: 2 additions & 2 deletions src/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ describe("CeloTransactionTypesPlugin", () => {
});

describe("isValidFeeCurrency()", () => {
test("l1", async () => {
test("l1", () => {
expect(web3.celo.isValidFeeCurrency("0x123")).resolves.toBe(false);
expect(
web3.celo.isValidFeeCurrency(
"0x874069Fa1Eb16D44d622F2e0Ca25eeA172369bC1"
)
).resolves.toBe(true);
});
test("l2", async () => {
test("l2", () => {
web3.setProvider(CeloChains.dango.rpcUrl);
expect(web3.celo.isValidFeeCurrency("0x123")).resolves.toBe(false);
expect(
Expand Down
47 changes: 30 additions & 17 deletions src/tests/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import {
} from "../utils";
import Web3 from "web3";
import { CeloTransactionTypesPlugin } from "..";
import {
testWithAnvilL1,
testWithAnvilL2,
} from "@celo/dev-utils/lib/anvil-test";

describe("CeloChains", () => {
test("chains should be configured", () => {
expect(CeloChains).toMatchSnapshot();
Expand All @@ -20,28 +25,36 @@ describe("Types", () => {
});
});

describe("getContractAddress()", () => {
const web3 = new Web3(CeloChains.alfajores.rpcUrl);
testWithAnvilL1("l1", (web3) => {
const plugin = new CeloTransactionTypesPlugin();
web3.registerPlugin(plugin);
test("returns a contract address", async () => {
expect(getContractAddress(plugin, "FeeCurrencyWhitelist")).resolves.toMatch(
/0x[0-9a-f]{40}/i
);

describe("getContractAddress()", () => {
test("returns a contract address", async () => {
expect(
getContractAddress(plugin, "FeeCurrencyWhitelist")
).resolves.toMatch(/0x[0-9a-f]{40}/i);
});
});
});

describe("isCel2()", () => {
test("l1", async () => {
const web3 = new Web3(CeloChains.alfajores.rpcUrl);
const plugin = new CeloTransactionTypesPlugin();
web3.registerPlugin(plugin);
describe("isCel2()", () => {
expect(isCel2(plugin)).resolves.toBe(false);
});
test("l2", async () => {
const web3 = new Web3(CeloChains.dango.rpcUrl);
const plugin = new CeloTransactionTypesPlugin();
web3.registerPlugin(plugin);
expect(isCel2(plugin)).resolves.toBe(true);
});

testWithAnvilL2("l2", (web3) => {
const plugin = new CeloTransactionTypesPlugin();
web3.registerPlugin(plugin);

describe("getContractAddress()", () => {
test("returns a contract address", async () => {
expect(
getContractAddress(plugin, "FeeCurrencyDirectory")
).resolves.toMatch(/0x[0-9a-f]{40}/i);
});
});

describe("isCel2()", () => {
expect(isCel2(plugin)).resolves.toBe(false);
});
});

0 comments on commit 070a5a1

Please sign in to comment.