-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
161 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env bash | ||
|
||
# This script installs Web3 from virtual registry in a | ||
# Windows env and runs some simple Web3 calls. | ||
|
||
# Exit immediately on error | ||
set -o errexit | ||
|
||
# Setup mock project to install web3 from virtual registry | ||
mkdir windows_test | ||
cp scripts/js/basic_usage.js windows_test/basic_usage.js | ||
cd windows_test | ||
|
||
# Install web3 as dep | ||
npm init --yes | ||
npm install web3@e2e --save --registry http://localhost:4873 | ||
node ./basic_usage.js | ||
|
||
# Shutdown verdaccio server | ||
cd .. | ||
source verdaccio_pid | ||
kill -9 $VERDACCIO_PID | ||
|
||
# Debugging... | ||
ps -ef |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env bash | ||
|
||
# This script contains conditional installation logic for Travis CI | ||
|
||
# CI jobs we'd like to skip default installation for: | ||
# Helpful for E2E tests where the dev deps might cause problems | ||
skip=( | ||
"e2e_ganache" | ||
"e2e_mosaic" | ||
"e2e_windows" | ||
) | ||
|
||
if [[ ! " ${skip[@]} " =~ " ${TEST} " ]]; then | ||
npm install | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#!/usr/bin/env node | ||
|
||
// This script runs some simple Web3 calls. | ||
// Useful for validating the published version in different OS environments. | ||
const Web3 = require('web3'); | ||
const util = require('util'); | ||
const log = console.log; | ||
|
||
async function delay(secs=0){ | ||
return new Promise(resolve => setTimeout(() => resolve(), secs * 1000)) | ||
} | ||
|
||
// A workaround for how flaky the infura connection can be... | ||
// Tries to fetch data 10x w/ 1 sec delays. Exits on first success. | ||
async function getBlockWithRetry(web3){ | ||
let i = 0; | ||
let block; | ||
|
||
while(true){ | ||
await delay(1); | ||
|
||
try { | ||
|
||
block = await web3.eth.getBlock('latest'); | ||
break; | ||
|
||
} catch(err){ | ||
|
||
i++; | ||
if (i === 10){ | ||
throw new Error('Failed to connect to Infura over websockets after 10 tries'); | ||
} | ||
|
||
} | ||
} | ||
return block; | ||
} | ||
|
||
async function main(){ | ||
let web3; | ||
let block; | ||
|
||
// Providers | ||
log(); | ||
log('>>>>>>'); | ||
log('HTTP:MAINNET getBlock'); | ||
log('>>>>>>'); | ||
|
||
// Http | ||
web3 = new Web3('https://mainnet.infura.io/v3/1d13168ffb894ad2827f2152620bd27c'); | ||
block = await getBlockWithRetry(web3); | ||
log(util.inspect(block)); | ||
|
||
log(); | ||
log('>>>>>>'); | ||
log('WS:MAINNET getBlock'); | ||
log('>>>>>>'); | ||
|
||
// WebSockets | ||
web3 = new Web3('wss://mainnet.infura.io/ws/v3/1d13168ffb894ad2827f2152620bd27c'); | ||
block = await getBlockWithRetry(web3); | ||
web3.currentProvider.disconnect(); | ||
log(util.inspect(block)); | ||
|
||
|
||
// Accounts | ||
web3 = new Web3(); | ||
|
||
log(); | ||
log('>>>>>>'); | ||
log('eth.accounts.createAccount'); | ||
log('>>>>>>'); | ||
|
||
const account = web3.eth.accounts.create(); | ||
log(util.inspect(account)); | ||
|
||
log(); | ||
log('>>>>>>'); | ||
log('eth.accounts.hashMessage'); | ||
log('>>>>>>'); | ||
|
||
const hash = web3.eth.accounts.hashMessage('Hello World'); | ||
log(util.inspect(hash)); | ||
} | ||
|
||
main() | ||
.then(() => process.exit(0)) | ||
.catch(err => { | ||
log(err); | ||
process.exit(1) | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters