From b5485f3f92604ffe93be755e8d6eefeedaa9621f Mon Sep 17 00:00:00 2001 From: duckception Date: Wed, 16 Aug 2023 21:51:11 +0200 Subject: [PATCH 1/4] Unskip tests for `*MetamaskToAddNetwork` and `*MetamaskToSwitchNetwork` --- docker-compose.ci.yml | 14 ++++++++++++++ docker-compose.yml | 14 ++++++++++++++ tests/e2e/specs/metamask-spec.js | 11 +++++------ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/docker-compose.ci.yml b/docker-compose.ci.yml index cd3701a00..82362154d 100644 --- a/docker-compose.ci.yml +++ b/docker-compose.ci.yml @@ -113,5 +113,19 @@ services: networks: - x11 + foundry-metamask-test-dapp: + profiles: + - foundry + container_name: foundry + image: synthetixio/foundry:457bb48776c3b14de232d9dda620ba9188dc40ac-base + # Port and chain id as required by the MetaMask Test Dapp + command: [ 'anvil --no-cors --port 8546 --chain-id 1338' ] + environment: + - ANVIL_IP_ADDR=0.0.0.0 + ports: + - '8546:8546' + networks: + - x11 + networks: x11: diff --git a/docker-compose.yml b/docker-compose.yml index 3a6ef7673..5d6dd666d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -84,5 +84,19 @@ services: networks: - x11 + foundry-metamask-test-dapp: + profiles: + - foundry + container_name: foundry + image: synthetixio/foundry:457bb48776c3b14de232d9dda620ba9188dc40ac-base + # Port and chain id as required by the MetaMask Test Dapp + command: [ 'anvil --no-cors --port 8546 --chain-id 1338' ] + environment: + - ANVIL_IP_ADDR=0.0.0.0 + ports: + - '8546:8546' + networks: + - x11 + networks: x11: diff --git a/tests/e2e/specs/metamask-spec.js b/tests/e2e/specs/metamask-spec.js index 56b073a58..79a4b186f 100644 --- a/tests/e2e/specs/metamask-spec.js +++ b/tests/e2e/specs/metamask-spec.js @@ -436,25 +436,24 @@ describe('Metamask', () => { expect(approved).to.be.true; }); }); - // todo: this feature is broken inside test-dapp, needs to be fixed (unable to switch to DAI chain) - it.skip(`rejectMetamaskToAddNetwork should reject permission to add network`, () => { + it(`rejectMetamaskToAddNetwork should reject permission to add network`, () => { cy.get('#addEthereumChain').click(); cy.rejectMetamaskToAddNetwork().then(rejected => { expect(rejected).to.be.true; }); }); - it.skip(`allowMetamaskToAddNetwork should approve permission to add network`, () => { + it(`allowMetamaskToAddNetwork should approve permission to add network`, () => { cy.get('#addEthereumChain').click(); - cy.allowMetamaskToAddNetwork('close').then(approved => { + cy.allowMetamaskToAddNetwork().then(approved => { expect(approved).to.be.true; }); }); - it.skip(`rejectMetamaskToSwitchNetwork should reject permission to switch network`, () => { + it(`rejectMetamaskToSwitchNetwork should reject permission to switch network`, () => { cy.rejectMetamaskToSwitchNetwork().then(rejected => { expect(rejected).to.be.true; }); }); - it.skip(`allowMetamaskToSwitchNetwork should approve permission to switch network`, () => { + it(`allowMetamaskToSwitchNetwork should approve permission to switch network`, () => { cy.get('#switchEthereumChain').click(); cy.allowMetamaskToSwitchNetwork().then(approved => { expect(approved).to.be.true; From 17e49cf637ceb05da1a108d2cc44de75b907f61d Mon Sep 17 00:00:00 2001 From: duckception Date: Wed, 16 Aug 2023 22:06:56 +0200 Subject: [PATCH 2/4] Update container names --- docker-compose.ci.yml | 2 +- docker-compose.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.ci.yml b/docker-compose.ci.yml index 82362154d..34efebf5c 100644 --- a/docker-compose.ci.yml +++ b/docker-compose.ci.yml @@ -116,7 +116,7 @@ services: foundry-metamask-test-dapp: profiles: - foundry - container_name: foundry + container_name: foundry-metamask-test-dapp image: synthetixio/foundry:457bb48776c3b14de232d9dda620ba9188dc40ac-base # Port and chain id as required by the MetaMask Test Dapp command: [ 'anvil --no-cors --port 8546 --chain-id 1338' ] diff --git a/docker-compose.yml b/docker-compose.yml index 5d6dd666d..a079a168d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -87,7 +87,7 @@ services: foundry-metamask-test-dapp: profiles: - foundry - container_name: foundry + container_name: foundry-metamask-test-dapp image: synthetixio/foundry:457bb48776c3b14de232d9dda620ba9188dc40ac-base # Port and chain id as required by the MetaMask Test Dapp command: [ 'anvil --no-cors --port 8546 --chain-id 1338' ] From 04b1336b04b9bd97bec055715d429e35aa056aae Mon Sep 17 00:00:00 2001 From: duckception Date: Wed, 16 Aug 2023 22:25:34 +0200 Subject: [PATCH 3/4] Add nginx for localhost redirections --- Dockerfile | 4 ++++ docker-compose.ci.yml | 2 +- docker-compose.yml | 2 +- nginx.conf | 25 +++++++++++++++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 nginx.conf diff --git a/Dockerfile b/Dockerfile index 3e7c94c1d..fc501b82d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,6 +4,10 @@ FROM --platform=linux/amd64 synthetixio/docker-e2e:18.16-ubuntu as base RUN mkdir /app WORKDIR /app +RUN apt update && apt install -y nginx + +COPY nginx.conf /etc/nginx/sites-available/default + COPY package.json ./ COPY pnpm-lock.yaml ./ diff --git a/docker-compose.ci.yml b/docker-compose.ci.yml index 34efebf5c..ff54fcd6d 100644 --- a/docker-compose.ci.yml +++ b/docker-compose.ci.yml @@ -43,7 +43,7 @@ services: - ./docker/videos:/app/tests/e2e/videos - ./docker/screenshots:/app/tests/e2e/screenshots command: > - bash -c 'echo -n "======> local noVNC URL: http://localhost:8080/vnc.html?autoconnect=true " && pnpm wait-on http://display:8080 && echo -n "======> remote noVNC URL: " && curl -s ngrok:4040/api/tunnels | jq -r .tunnels[0].public_url && pnpm test:e2e:ci:anvil' + bash -c 'echo -n "======> local noVNC URL: http://localhost:8080/vnc.html?autoconnect=true " && pnpm wait-on http://display:8080 && echo -n "======> remote noVNC URL: " && curl -s ngrok:4040/api/tunnels | jq -r .tunnels[0].public_url && nginx && pnpm test:e2e:ci:anvil' networks: - x11 diff --git a/docker-compose.yml b/docker-compose.yml index a079a168d..82c798060 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -21,7 +21,7 @@ services: - ./docker/videos:/app/tests/e2e/videos - ./docker/screenshots:/app/tests/e2e/screenshots command: > - bash -c 'echo -n "======> local noVNC URL: http://localhost:8080/vnc.html?autoconnect=true " && pnpm wait-on http://display:8080 && echo -n "======> remote noVNC URL: " && curl -s ngrok:4040/api/tunnels | jq -r .tunnels[0].public_url && pnpm test:e2e:anvil' + bash -c 'echo -n "======> local noVNC URL: http://localhost:8080/vnc.html?autoconnect=true " && pnpm wait-on http://display:8080 && echo -n "======> remote noVNC URL: " && curl -s ngrok:4040/api/tunnels | jq -r .tunnels[0].public_url && nginx && pnpm test:e2e:anvil' networks: - x11 diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 000000000..0d1751215 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,25 @@ +server { + listen 8545; + server_name localhost; + + location / { + proxy_pass http://foundry:8545; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } +} + +server { + listen 8546; + server_name localhost; + + location / { + proxy_pass http://foundry-metamask-test-dapp:8546; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } +} From a9235447f30be6e848f53347c7db076285beff52 Mon Sep 17 00:00:00 2001 From: duckception Date: Thu, 17 Aug 2023 02:08:24 +0200 Subject: [PATCH 4/4] Remove conditional rpc url in test --- tests/e2e/specs/metamask-spec.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/e2e/specs/metamask-spec.js b/tests/e2e/specs/metamask-spec.js index 79a4b186f..ed8953e72 100644 --- a/tests/e2e/specs/metamask-spec.js +++ b/tests/e2e/specs/metamask-spec.js @@ -58,9 +58,7 @@ describe('Metamask', () => { if (Cypress.env('USE_ANVIL')) { cy.addMetamaskNetwork({ networkName: 'anvil', - rpcUrl: Cypress.env('DOCKER_RUN') - ? 'http://foundry:8545' - : 'http://127.0.0.1:8545', + rpcUrl: 'http://127.0.0.1:8545', chainId: 11155111, symbol: 'aETH', isTestnet: true,