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

reset hardhat script WIP #195

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
52 changes: 52 additions & 0 deletions scripts/resetHardhat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const axios = require('axios');
const fs = require("fs");

const takeSnapshot = async () => {
try{
const [remoteHardhatUrl] = process.argv.slice(2);
const {data} = await axios.post(remoteHardhatUrl, {
"jsonrpc":"2.0",
"method":"evm_snapshot",
"params":[],
"id":1
})
console.log('snapshotId: ', data.result)
fs.writeFileSync('./tests/snapshot-id.txt', data.result)
console.log('all done')
process.exit(0)
} catch (e) {
console.error(e)
process.exit(1)
}
};

const run = async () => {
try{
const [remoteHardhatUrl] = process.argv.slice(2);
if(!remoteHardhatUrl){
throw new Error('please include the remote hardhat url as an argument')
}
console.log('remote hardhat url: ', remoteHardhatUrl)
const snapshotId = fs.readFileSync('./tests/snapshot-id.txt', 'utf8')
if (!snapshotId){

}
console.log('snapshotId: ', snapshotId)

const {data} = await axios.post(remoteHardhatUrl, {
"jsonrpc":"2.0",
"method":"evm_revert",
"params":[snapshotId],
"id":1
})

console.log('revert success: ', data.result)
console.log('all done')
process.exit(0)
} catch (e) {
console.error(e)
process.exit(1)
}
};

run();
30 changes: 30 additions & 0 deletions scripts/revertSnapshot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const axios = require('axios');
const fs = require("fs");

const run = async () => {
try{
const [remoteHardhatUrl] = process.argv.slice(2);
if(!remoteHardhatUrl){
throw new Error('please include the remote hardhat url as an argument')
}
console.log('remote hardhat url: ', remoteHardhatUrl)
const snapshotId = fs.readFileSync('./tests/snapshot-id.txt', 'utf8')
console.log('snapshotId: ', snapshotId)

const {data} = await axios.post(remoteHardhatUrl, {
"jsonrpc":"2.0",
"method":"evm_revert",
"params":[snapshotId],
"id":1
})

console.log('revert success: ', data.result)
console.log('all done')
process.exit(0)
} catch (e) {
console.error(e)
process.exit(1)
}
};

run();
27 changes: 27 additions & 0 deletions scripts/takeShanpshot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const axios = require('axios');
const fs = require("fs");

const run = async () => {
try{
const [remoteHardhatUrl] = process.argv.slice(2);
if(!remoteHardhatUrl){
throw new Error('please include the remote hardhat url as an argument')
}
console.log('remote hardhat url: ', remoteHardhatUrl)
const {data} = await axios.post(remoteHardhatUrl, {
"jsonrpc":"2.0",
"method":"evm_snapshot",
"params":[],
"id":1
})
console.log('snapshotId: ', data.result)
fs.writeFileSync('./tests/snapshot-id.txt', data.result)
console.log('all done')
process.exit(0)
} catch (e) {
console.error(e)
process.exit(1)
}
};

run();
98 changes: 98 additions & 0 deletions tests/e2e/specs/_reset-hardhat-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
describe('intial setup', () => {
before('resets hardhat', () => {
//read snapshot
cy.readFile('./tests/snapshot-id.txt')
.then(snapshotId => {
// revert to snapshot
return cy.request("POST", "http://localhost:8545", {
"jsonrpc":"2.0",
"method":"evm_revert",
"params":[snapshotId],
"id":1
})
})
.then(({body})=> {
cy.log("revert success: " + body.result)
})

cy.wait(4*1000)
// take new snapshot
cy.request("POST", "http://localhost:8545", {
"jsonrpc":"2.0",
"method":"eth_blockNumber",
"params":[],
"id":1
})
.then(({body})=> {
cy.log("eth_blockNumber: " + body.result)
return cy.request("POST", "http://localhost:8545", {
"jsonrpc":"2.0",
"method":"evm_snapshot",
"params":[body.result],
"id":1
})
})
.then(({body})=> {
cy.log("snapshot-id.txt: " + body.result)
// write snapshot to disk
return cy.writeFile('./tests/snapshot-id.txt', body.result)
})

cy.log("snapshot done! ")

cy.request("POST", "http://localhost:8545", {
"jsonrpc":"2.0",
"method":"mine_block",
"params":[],
"id":1
})

cy.request("POST", "http://localhost:8545", {
"jsonrpc":"2.0",
"method":"mine_block",
"params":[],
"id":1
})

cy.request("POST", "http://localhost:8545", {
"jsonrpc":"2.0",
"method":"mine_block",
"params":[],
"id":1
})

cy.request("POST", "http://localhost:8545", {
"jsonrpc":"2.0",
"method":"mine_block",
"params":[],
"id":1
})

cy.request("POST", "http://localhost:8545", {
"jsonrpc":"2.0",
"method":"mine_block",
"params":[],
"id":1
})
cy.log("mined 5 blocks")
})

it('validates address', () => {
cy.getMetamaskWalletAddress().then(address => {
expect(address).to.equal("0xF994Eba5f3F33EbC5a03d9B5e195765eeb29a923")
})
})

it('validates balance', () => {
cy.resetMetamaskAccount() // fix
cy.visit('/')
cy.contains('Connect').click()
cy.contains('Meta Mask').click()
cy.wait(4 * 1000)
cy.acceptMetamaskAccess()
cy.wait(4 * 1000)
cy.contains("Deposit").click()
cy.wait(4 * 1000)
cy.contains("1111 ETH")
})
})