Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
794d6265
Unverified
Commit
794d6265
authored
Sep 05, 2023
by
Wyatt Barnes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Init Metmask send tx test
parent
81882115
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
110 additions
and
7 deletions
+110
-7
.env.example
ufm-test-services/metamask/.env.example
+2
-0
.gitignore
ufm-test-services/metamask/.gitignore
+1
-0
package.json
ufm-test-services/metamask/package.json
+4
-2
pnpm-lock.yaml
ufm-test-services/metamask/pnpm-lock.yaml
+3
-0
metamask.spec.ts
ufm-test-services/metamask/tests/metamask.spec.ts
+100
-4
testWithSynpressUtil.ts
ufm-test-services/metamask/tests/testWithSynpressUtil.ts
+0
-1
No files found.
ufm-test-services/metamask/.env.example
View file @
794d6265
...
@@ -2,3 +2,5 @@ METAMASK_SECRET_WORDS_OR_PRIVATEKEY=""
...
@@ -2,3 +2,5 @@ METAMASK_SECRET_WORDS_OR_PRIVATEKEY=""
METAMASK_NETWORK="goerli"
METAMASK_NETWORK="goerli"
METAMASK_PASSWORD="Test@1234"
METAMASK_PASSWORD="Test@1234"
METAMASK_DAPP_URL="http://localhost:9011"
METAMASK_DAPP_URL="http://localhost:9011"
OP_GOERLI_RPC_URL=""
ufm-test-services/metamask/.gitignore
View file @
794d6265
...
@@ -2,3 +2,4 @@ node_modules/
...
@@ -2,3 +2,4 @@ node_modules/
/test-results/
/test-results/
/playwright-report/
/playwright-report/
/playwright/.cache/
/playwright/.cache/
.env
ufm-test-services/metamask/package.json
View file @
794d6265
...
@@ -14,7 +14,8 @@
...
@@ -14,7 +14,8 @@
"clean"
:
"rm -rf node_modules packages/*/node_modules && echo 'Finished cleaning'"
,
"clean"
:
"rm -rf node_modules packages/*/node_modules && echo 'Finished cleaning'"
,
"lint"
:
"prettier --check ."
,
"lint"
:
"prettier --check ."
,
"lint:fix"
:
"prettier --write ."
,
"lint:fix"
:
"prettier --write ."
,
"start:metamask-dapp"
:
"npx static-server node_modules/@metamask/test-dapp/dist --port 9011"
"start:metamask-dapp"
:
"npx static-server node_modules/@metamask/test-dapp/dist --port 9011"
,
"test"
:
"npx playwright test"
},
},
"devDependencies"
:
{
"devDependencies"
:
{
"@metamask/test-dapp"
:
"^7.1.0"
,
"@metamask/test-dapp"
:
"^7.1.0"
,
...
@@ -22,6 +23,7 @@
...
@@ -22,6 +23,7 @@
"@synthetixio/synpress"
:
"3.7.2-beta.5"
,
"@synthetixio/synpress"
:
"3.7.2-beta.5"
,
"dotenv"
:
"^16.3.1"
,
"dotenv"
:
"^16.3.1"
,
"static-server"
:
"^2.2.1"
,
"static-server"
:
"^2.2.1"
,
"typescript"
:
"^5.1.6"
"typescript"
:
"^5.1.6"
,
"viem"
:
"^1.10.8"
}
}
}
}
ufm-test-services/metamask/pnpm-lock.yaml
View file @
794d6265
...
@@ -26,6 +26,9 @@ importers:
...
@@ -26,6 +26,9 @@ importers:
typescript
:
typescript
:
specifier
:
^5.1.6
specifier
:
^5.1.6
version
:
5.1.6
version
:
5.1.6
viem
:
specifier
:
^1.10.8
version
:
1.10.8(typescript@5.1.6)
packages
:
packages
:
...
...
ufm-test-services/metamask/tests/metamask.spec.ts
View file @
794d6265
import
{
testWithSynpress
}
from
'
./testWithSynpress
'
import
'
dotenv/config
'
import
{
test
}
from
'
@playwright/test
'
import
metamask
from
'
@synthetixio/synpress/commands/metamask.js
'
import
{
expect
,
test
,
type
Page
}
from
'
@playwright/test
'
import
{
mnemonicToAccount
,
privateKeyToAccount
}
from
'
viem/accounts
'
testWithSynpress
(
'
should be able to read
'
,
async
({
page
})
=>
{
import
{
testWithSynpress
}
from
'
./testWithSynpressUtil
'
await
page
.
goto
(
'
http://localhost:9011
'
)
const
expectedSender
=
process
.
env
.
METAMASK_SECRET_WORDS_OR_PRIVATEKEY
?.
startsWith
(
'
0x
'
)
?
privateKeyToAccount
(
process
.
env
.
METAMASK_SECRET_WORDS_OR_PRIVATEKEY
as
`0x
${
string
}
`
).
address
.
toLowerCase
()
:
mnemonicToAccount
(
process
.
env
.
METAMASK_SECRET_WORDS_OR_PRIVATEKEY
as
string
).
address
.
toLowerCase
()
const
expectedRecipient
=
'
0x8fcfbe8953433fd1f2e8375ee99057833e4e1e9e
'
let
sharedPage
:
Page
test
.
describe
.
configure
({
mode
:
'
serial
'
})
test
.
afterAll
(
async
()
=>
{
await
sharedPage
.
close
()
})
testWithSynpress
(
'
Setup wallet and dApp
'
,
async
({
page
})
=>
{
sharedPage
=
page
await
sharedPage
.
goto
(
'
http://localhost:9011
'
)
})
testWithSynpress
(
'
Add OP Goerli network
'
,
async
()
=>
{
const
expectedChainId
=
'
0x1a4
'
await
metamask
.
addNetwork
({
name
:
'
op-goerli
'
,
rpcUrls
:
{
default
:
{
http
:
[
process
.
env
.
OP_GOERLI_RPC_URL
],
},
},
id
:
'
420
'
,
nativeCurrency
:
{
symbol
:
'
OPG
'
,
},
blockExplorers
:
{
default
:
{
url
:
'
https://goerli-explorer.optimism.io
'
,
},
},
})
await
expect
(
sharedPage
.
locator
(
'
#chainId
'
)).
toHaveText
(
expectedChainId
)
})
test
(
`Connect wallet with
${
expectedSender
}
`
,
async
()
=>
{
await
sharedPage
.
click
(
'
#connectButton
'
)
await
metamask
.
acceptAccess
()
await
expect
(
sharedPage
.
locator
(
'
#accounts
'
)).
toHaveText
(
expectedSender
)
})
test
(
'
Send an EIP-1559 transaciton and verfiy success
'
,
async
()
=>
{
const
expectedTransferAmount
=
'
0x1
'
const
expectedTxType
=
'
0x2
'
await
sharedPage
.
locator
(
'
#toInput
'
).
fill
(
expectedRecipient
)
await
sharedPage
.
locator
(
'
#amountInput
'
).
fill
(
expectedTransferAmount
)
await
sharedPage
.
locator
(
'
#typeInput
'
).
selectOption
(
expectedTxType
)
await
sharedPage
.
click
(
'
#submitForm
'
)
const
txHashPromise
=
new
Promise
((
resolve
)
=>
{
// Metamask test dApp only console.logs the transaction hash,
// so we must setup a listener before we confirm the tx to capture it
sharedPage
.
on
(
'
console
'
,
async
(
msg
)
=>
{
resolve
(
msg
.
text
())
// Resolve the Promise when txHash is set
})
})
await
metamask
.
confirmTransaction
()
const
txHash
=
await
txHashPromise
// Waiting for Infura (Metamask given provider) to index our transaction
await
sharedPage
.
waitForTimeout
(
2
_000
)
// Metamask test dApp allows us access to the Metamask RPC provider via loading this URL.
// The RPC reponse will be populated onto the page that's loaded.
// More info here: https://github.com/MetaMask/test-dapp/tree/main#usage
await
sharedPage
.
goto
(
`
${
process
.
env
.
METAMASK_DAPP_URL
}
/request.html?method=eth_getTransactionReceipt¶ms=["
${
txHash
}
"]`
)
// Waiting for RPC response to be populated on the page
await
sharedPage
.
waitForTimeout
(
2
_000
)
const
transaction
=
JSON
.
parse
(
(
await
sharedPage
.
locator
(
'
body > main
'
).
innerText
()).
replace
(
'
Response:
'
,
''
)
)
expect
(
transaction
.
status
).
toBe
(
'
0x1
'
)
})
})
ufm-test-services/metamask/tests/testWithSynpress.ts
→
ufm-test-services/metamask/tests/testWithSynpress
Util
.ts
View file @
794d6265
...
@@ -48,7 +48,6 @@ export const testWithSynpress = base.extend<{
...
@@ -48,7 +48,6 @@ export const testWithSynpress = base.extend<{
enableAdvancedSettings
:
true
,
enableAdvancedSettings
:
true
,
})
})
await
use
(
context
)
await
use
(
context
)
await
context
.
close
()
},
},
})
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment