Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support sepolia testnet #61

Merged
merged 37 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
26ab5a9
chore: change ropsten to sepolia
zixiang2018 Sep 27, 2023
abfd48e
feat: bump ethers version
zixiang2018 Sep 27, 2023
6641afe
chore: update typings
zixiang2018 Sep 27, 2023
0f3f3ce
chore: validate gasPrice and nonce existence
zixiang2018 Sep 28, 2023
aa3bccc
chore: attempt to use older puppeteer-headful
zixiang2018 Sep 28, 2023
b18d0f0
Revert "chore: attempt to use older puppeteer-headful"
zixiang2018 Sep 28, 2023
04c71f7
chore: node 18
zixiang2018 Sep 28, 2023
7327c3e
chore: factory requires an address param
zixiang2018 Sep 28, 2023
e0ab149
chore: use chainsafe/dappeteer
zixiang2018 Sep 28, 2023
9861920
chore: use latest puppeteer related packages
zixiang2018 Sep 28, 2023
c3211b9
chore: refine errors
zixiang2018 Sep 28, 2023
834bf88
chore: add openssl legacy provider
zixiang2018 Sep 28, 2023
5d32005
chore: check for node >=17
zixiang2018 Sep 28, 2023
eab4d01
chore: openssl legacy provider
zixiang2018 Sep 28, 2023
6aaccbf
chore: add env var into command directly
zixiang2018 Sep 28, 2023
5a16512
chore: remove openssl legacy provider
zixiang2018 Sep 28, 2023
545e92f
chore: use ganache
zixiang2018 Sep 28, 2023
95a6b69
chore: remove react-scripts
zixiang2018 Sep 28, 2023
d88b027
chore: update wait-on
zixiang2018 Sep 28, 2023
72d00c8
chore: update actions
zixiang2018 Sep 28, 2023
f168b0b
chore: npm i
zixiang2018 Sep 28, 2023
4af93ec
chore: upgrade vite
zixiang2018 Sep 28, 2023
fbff2ca
chore: add timeout
zixiang2018 Sep 28, 2023
065f4ac
chore: update port
zixiang2018 Sep 28, 2023
50286b5
chore add verbose wait-on
zixiang2018 Sep 28, 2023
fac6537
chore: fix package import
zixiang2018 Sep 28, 2023
f625c4e
chore: fix tests
zixiang2018 Oct 2, 2023
1d25648
chore: npm run test
zixiang2018 Oct 2, 2023
efbe326
chore: tweak metamask init
zixiang2018 Oct 2, 2023
879ba54
chore: tweak
zixiang2018 Oct 2, 2023
79361a9
chore: refine
zixiang2018 Oct 2, 2023
8bda9a2
chore: add browser close
zixiang2018 Oct 2, 2023
238f13e
chore: change ports
zixiang2018 Oct 2, 2023
a8c63cd
chore: remove comment
zixiang2018 Oct 3, 2023
a9146e7
chore: add port to dev
zixiang2018 Oct 3, 2023
6abac24
chore: update error handling
zixiang2018 Oct 3, 2023
86f852b
chore: refactor
zixiang2018 Oct 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ jobs:
test:
name: Lint & Test
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: '14'

node-version: '18'
- name: Cache Node Modules
uses: actions/cache@v2
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
Expand Down
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
Administration Website v2 will be removing ledger flow. For users that continue using the hardware ledger, you could link the hardware ledgers using the Metamask chrome extension plugin and perform the functionality as per normal.

See also:
* [admin-website](https://github.com/OpenCerts/admin-website)
* [document-store](https://github.com/Open-Attestation/document-store)
* [open-attestation-cli](https://github.com/Open-Attestation/open-attestation-cli)

- [admin-website](https://github.com/OpenCerts/admin-website)
- [document-store](https://github.com/Open-Attestation/document-store)
- [open-attestation-cli](https://github.com/Open-Attestation/open-attestation-cli)

## Development Setup

We develop primarily on a OS / Linux environment so please lodge an issue if you are using Windows and find that you cannot successfully set up a local instance of this software.

```bash
Expand All @@ -16,6 +18,7 @@ npm run start
```

## Jest Test

Jest test validate the common utility function.

```bash
Expand All @@ -24,18 +27,18 @@ npm run test

## Integration Dappeteer Test

Dappeteer test perform e2e test on issue and revoke functionality using local blockchain running on ganache-cli. The test can be executed using the command below.
Dappeteer test perform e2e test on issue and revoke functionality using local blockchain running on ganache. The test can be executed using the command below.

```bash
npm run integration:dappeteer
```

The speed of the testing can be modified using this options.

- First argument : Slowing of testing speed. (higher number = slower test)

```bash
npm run integration:dappeteer 50
```

Note that current dappeteer integration test uses mujo-code/puppeteer-headful@master that run on v12.10 node docker. v14 node version is required to remove --experimental-modules flag from integration:transfers command.

27 changes: 27 additions & 0 deletions integration/addNetwork.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export const addNetwork = async () => {
const addNetworkRequest = window.ethereum.request({
method: "wallet_addEthereumChain",
params: [
{
chainId: "0x539",
chainName: "Localhost 8545",
nativeCurrency: {
name: "ETH",
symbol: "ETH",
decimals: 18,
},
rpcUrls: ["http://localhost:8545"],
},
],
});

return new Promise((resolve) => {
addNetworkRequest
.then(() => {
resolve(true);
})
.catch(() => {
resolve(false);
});
});
};
14 changes: 9 additions & 5 deletions integration/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ import { metamaskInit } from "./metamask-init.mjs";
const issueAndRevoke = async () => {
const { metamask, browser } = await metamaskInit();

await issue(metamask, browser);
await revoke(metamask, browser);

await browser.close();
process.exit(0);
try {
await issue(metamask, browser);
await revoke(metamask, browser);
} catch (e) {
console.error(e);
} finally {
browser.close();
process.exit(0);
}
};

issueAndRevoke();
49 changes: 23 additions & 26 deletions integration/issue.mjs
Original file line number Diff line number Diff line change
@@ -1,47 +1,44 @@
import expect from "expect-puppeteer";
import { expect } from "chai";
import { sleep, waitForAndClickElement, waitForElement } from "./utils.mjs";

export const issue = async (metamask, browser) => {
try {
const page = await browser.newPage();
await page.goto("http://localhost:5000/");
await page.goto("http://localhost:4173/", { waitUntil: "networkidle" });

// START - approve application once, subsequent tests no longer need
await metamask.approve({ allAccounts: true });
await metamask.approve();
await page.bringToFront();
// END - approve application once, subsequent tests no longer need
await page.waitForSelector("[data-testid='connectToWallet']", {
visible: true,
});
await page.click("[data-testid='connectToWallet']");
await waitForAndClickElement(page, "[data-testid='connectToWallet']");

await page.waitForSelector("[aria-controls='react-autowhatever-document-store']", {
visible: true,
});
await page.focus("[aria-controls='react-autowhatever-document-store']");
await page.keyboard.type("0xC84b0719A82626417c40f3168513dFABDB6A9079");
await waitForAndClickElement(page, ".react-autosuggest__input");
await page.type(".react-autosuggest__input", "0xC84b0719A82626417c40f3168513dFABDB6A9079");

// Test user successfully issue the transaction
await page.waitForSelector("[data-testid='issue-certificate']", {
visible: true,
});
await page.focus("[data-testid='issue-certificate']");
await page.keyboard.type("0xbabf7285760d279e6dfa9c37d97bd3f77025a0be0e74119ff24ac9ee0739c60b");
await waitForElement(page, "[data-testid='issue-certificate']");
await page.type(
"[data-testid='issue-certificate']",
"0xbabf7285760d279e6dfa9c37d97bd3f77025a0be0e74119ff24ac9ee0739c60b"
);

await page.waitForSelector("[data-testid='issue-certificate-btn']", {
visible: true,
});
await page.click("[data-testid='issue-certificate-btn']");
await waitForAndClickElement(page, "[data-testid='issue-certificate-btn']");

await page.waitFor(1500);
await sleep(1500);
await metamask.confirmTransaction();
await page.bringToFront();
await page.waitFor(3000);
await sleep(3000);

await expect(page).toMatchElement("[data-testid='issue-log']", {
text: `Document/Document Batch with hash 0xbabf7285760d279e6dfa9c37d97bd3f77025a0be0e74119ff24ac9ee0739c60b has been issued to 0xC84b0719A82626417c40f3168513dFABDB6A9079.`,
visible: true,
await waitForElement(page, "[data-testid='issue-log']");
const issueLog = await page.evaluate(() => {
const el = document.querySelector("[data-testid='issue-log']");
return el.textContent;
});

await expect(issueLog).to.have.string(
"Document/Document Batch with hash 0xbabf7285760d279e6dfa9c37d97bd3f77025a0be0e74119ff24ac9ee0739c60b has been issued to 0xC84b0719A82626417c40f3168513dFABDB6A9079."
);

await page.close();
console.info("✅ Issue success");
} catch (e) {
Expand Down
47 changes: 37 additions & 10 deletions integration/metamask-init.mjs
Original file line number Diff line number Diff line change
@@ -1,19 +1,46 @@
import puppeteer from "puppeteer";
import dappeteer from "dappeteer";
import dappeteer from "@chainsafe/dappeteer";
import { addNetwork } from "./addNetwork.mjs";
import { sleep } from "./utils.mjs";

export const metamaskInit = async () => {
try {
const browser = await dappeteer.launch(puppeteer, {
args: ["--no-sandbox"],
executablePath: process.env.PUPPETEER_EXEC_PATH,
headless: false, // must be false, so can test with metamask extension
defaultViewport: null,
slowMo: process.argv[2] || 0,
const browser = await dappeteer.launch({
metaMaskVersion: "v10.31.0",
automation: "puppeteer",
headless: false,
puppeteerOptions: {
args: ["--no-sandbox"],
executablePath: process.env.PUPPETEER_EXEC_PATH,
defaultViewport: null,
slowMo: process.argv[2] || 0,
},
});
const metamask = await dappeteer.getMetamask(browser, {

await sleep(2000);
const pages = await browser.pages();
for (const page of pages) {
if (page.url().startsWith("chrome-extension")) {
await page.reload();
}
}

// Get metamask
const metamask = await dappeteer.setupMetaMask(browser, {
seed: "indicate swing place chair flight used hammer soon photo region volume shuffle",
showTestNets: true,
});
await metamask.switchNetwork("localhost");

// Add network
// https://github.com/ChainSafe/dappeteer/blob/b79ab4c74fab87747933d8f428624dcbffc3dd19/test/basic.spec.ts#L117-L119
const dappPage = await browser.newPage();
await dappPage.goto("https://github.com", { waitUntil: "networkidle" });
dappPage.evaluate(addNetwork);

try {
await metamask.acceptAddNetwork(true);
} catch (e) {
// ignore error
}

console.info("✅ Metamask account init success");
return { metamask, browser };
Expand Down
61 changes: 28 additions & 33 deletions integration/revoke.mjs
Original file line number Diff line number Diff line change
@@ -1,51 +1,46 @@
import expect from "expect-puppeteer";
import { expect } from "chai";
import { sleep, waitForAndClickElement, waitForElement } from "./utils.mjs";

export const revoke = async (metamask, browser) => {
try {
const page = await browser.newPage();
await page.goto("http://localhost:5000/");
await page.goto("http://localhost:4173/");

await page.waitForSelector("[data-testid='connectToWallet']", {
visible: true,
});
await page.click("[data-testid='connectToWallet']");
await waitForAndClickElement(page, "[data-testid='connectToWallet']");

await page.waitForSelector("[aria-controls='react-autowhatever-document-store']", {
visible: true,
});
await page.focus("[aria-controls='react-autowhatever-document-store']");
await page.keyboard.type("0xC84b0719A82626417c40f3168513dFABDB6A9079");
await waitForAndClickElement(page, ".react-autosuggest__input");
await page.type(".react-autosuggest__input", "0xC84b0719A82626417c40f3168513dFABDB6A9079");

await page.waitForSelector("[data-testid='show-revoke-btn']", {
visible: true,
});
await page.click("[data-testid='show-revoke-btn']");
await waitForAndClickElement(page, "[data-testid='show-revoke-btn']");

await page.waitForSelector("[data-testid='revoke-certificate']", {
visible: true,
});
await page.focus("[data-testid='revoke-certificate']");
await page.keyboard.type("0xbabf7285760d279e6dfa9c37d97bd3f77025a0be0e74119ff24ac9ee0739c60b");
await waitForElement(page, "[data-testid='revoke-certificate']");
await page.type(
"[data-testid='revoke-certificate']",
"0xbabf7285760d279e6dfa9c37d97bd3f77025a0be0e74119ff24ac9ee0739c60b"
);

await page.waitForSelector("[data-testid='revoke-btn']", {
visible: true,
});
await page.click("[data-testid='revoke-btn']");
await waitForElement(page, "[data-testid='revoke-btn']");

await page.waitForSelector("[data-testid='confirm-revoke-btn']", {
visible: true,
});
await page.click("[data-testid='confirm-revoke-btn']");
await page.waitFor(1500);
await waitForAndClickElement(page, "[data-testid='revoke-btn']");

await waitForAndClickElement(page, "[data-testid='confirm-revoke-btn']");

await sleep(1500);
await metamask.confirmTransaction();
await page.bringToFront();
await page.waitFor(3000);
await sleep(3000);

await expect(page).toMatchElement("[data-testid='revoke-log']", {
text: "Document/Document Batch with hash 0xbabf7285760d279e6dfa9c37d97bd3f77025a0be0e74119ff24ac9ee0739c60b has been revoked on 0xC84b0719A82626417c40f3168513dFABDB6A9079",
visible: true,
await waitForElement(page, "[data-testid='revoke-log']");

const revokeLog = await page.evaluate(() => {
const el = document.querySelector("[data-testid='revoke-log']");
return el.textContent;
});

await expect(revokeLog).to.have.string(
"Document/Document Batch with hash 0xbabf7285760d279e6dfa9c37d97bd3f77025a0be0e74119ff24ac9ee0739c60b has been revoked on 0xC84b0719A82626417c40f3168513dFABDB6A9079"
);

await page.close();
console.info("✅ Revoke success");
} catch (e) {
Expand Down
13 changes: 13 additions & 0 deletions integration/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export const waitForAndClickElement = async (page, query) => {
await waitForElement(page, query);
const element = await page.$(query);
await element.click();
};

export const waitForElement = async (page, query) => {
await page.waitForSelector(query, {
visible: true,
});
};

export const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
HJunyuan marked this conversation as resolved.
Show resolved Hide resolved
Loading