Skip to content

Commit

Permalink
fix: various fixes and e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasbrugneaux committed Aug 27, 2024
1 parent 8cadc5b commit dd3f1aa
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
!.eslintrc.js
!jest.config.js
lib
*.tsbuildinfo
*.tsbuildinfo.env
.env
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"types": "./lib/index.d.ts",
"sideEffects": false,
"homepage": "https://docs.celo.org/developer/TODO",
"repository": "https://github.com/celo-org/developer-tooling/tree/master/packages/third-party/web3-plugin",
"repository": "https://github.com/celo-org/web3-plugin-transaction-types",
"scripts": {
"prepublishOnly": "bun run clean && bun run build",
"build": "bun run tsc -b .",
Expand All @@ -30,6 +30,8 @@
"@celo/dev-utils": "^0.0.5",
"@celo/devchain-anvil": "11.0.0-canary.0",
"@celo/typescript": "^0.0.2",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.7",
"@types/bun": "^1.1.6",
"eslint": "^9.8.0",
"eslint-plugin-jest": "^28.6.0",
Expand Down
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,7 @@ declare module "web3" {
interface Web3Context {
celo: CeloTransactionTypesPlugin;
}
interface NonPayableCallOptions {
feeCurrency?: Address;
}
}
2 changes: 2 additions & 0 deletions src/tests/__snapshots__/utils.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ exports[`Types tx types should be configured 1`] = `
"ethereum-legacy": "",
}
`;

exports[`l2 getContractAddressFromRegistry() throws if doesn't exists 1`] = `[Error: Contract not found with name FAKE CONTRACT NAME]`;
17 changes: 15 additions & 2 deletions src/tests/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ testWithAnvilL1("l1", (web3) => {
test("returns a contract address", async () => {
expect(
getContractAddressFromRegistry(plugin, "FeeCurrencyWhitelist")
).resolves.toMatch(/0x[0-9a-f]{40}/i);
).resolves.toMatch(/^0x[0-9a-f]{40}$/i);
});
});

Expand All @@ -57,7 +57,20 @@ testWithAnvilL2("l2", (web3) => {
test("returns a contract address", async () => {
expect(
getContractAddressFromRegistry(plugin, "FeeCurrencyDirectory")
).resolves.toMatch(/0x[0-9a-f]{40}/i);
).resolves.toMatch(/^0x[0-9a-f]{40}$/i);
});
test("returns a non zero contract address", async () => {
const address = await getContractAddressFromRegistry(
plugin,
"StableTokenEUR"
);
expect(address).toMatch(/^0x[0-9a-f]{40}$/i);
expect(BigInt(address)).not.toEqual(0n);
});
test("throws if doesn't exists", async () => {
expect(
getContractAddressFromRegistry(plugin, "FAKE CONTRACT NAME")
).rejects.toMatchSnapshot();
});
});

Expand Down
3 changes: 3 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export const getContractAddressFromRegistry = async (
.getAddressForString(contractName)
.call();

if (BigInt(address) === BigInt(0)) {
throw new Error(`Contract not found with name ${contractName}`);
}
return address;
};

Expand Down

0 comments on commit dd3f1aa

Please sign in to comment.