-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from keep-network/e2e-test
tBTC end-to-end test script
- Loading branch information
Showing
23 changed files
with
30,445 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.idea | ||
/ethereum/data/geth/ | ||
/storage/ | ||
/storage/ | ||
node_modules |
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,7 @@ | ||
{ | ||
"protocol": "http", | ||
"host": "10.102.100.252", | ||
"port": "18332", | ||
"user": "x", | ||
"pass": "backwardskeymyisthis" | ||
} |
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,19 @@ | ||
SUMMA_RELAY_ETHER_HOST=localhost | ||
|
||
SUMMA_RELAY_ETHER_PORT=8545 | ||
|
||
SUMMA_RELAY_OPERATOR_KEY=d6ce6a6ca295bbef9ddee79e583fabdcdd98290bbea2dc03ff8317ccf70d3f87 | ||
|
||
SUMMA_RELAY_ETH_NETWORK=internal | ||
|
||
SUMMA_RELAY_ETH_CHAIN_ID=1101 | ||
|
||
SUMMA_RELAY_BCOIN_HOST=10.102.100.252 | ||
|
||
SUMMA_RELAY_BCOIN_API_KEY=backwardskeymyisthis | ||
|
||
SUMMA_RELAY_BCOIN_PORT=18332 | ||
|
||
SUMMA_RELAY_INFURA_KEY="" | ||
|
||
SUMMA_RELAY_CONTRACT=RELAYCONTRACT |
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,135 @@ | ||
#!/usr/bin/env node --experimental-modules | ||
|
||
import Web3 from "web3" | ||
import ProviderEngine from "web3-provider-engine" | ||
import WebsocketSubprovider from "web3-provider-engine/subproviders/websocket.js" | ||
import TBTC from "@keep-network/tbtc.js" | ||
import Subproviders from "@0x/subproviders" | ||
|
||
const depositsCount = 2 | ||
const satoshiLotSize = 100000 // 0.001 BTC | ||
const btcAddress = '2N6L4Q6fphMzuWqERQYTwgEMmQTpcqgdVFK' | ||
|
||
const engine = new ProviderEngine({ pollingInterval: 1000 }) | ||
|
||
engine.addProvider( | ||
// Private key of address 0xd6b0a1ca8f0641b97efec0f1ed73d72e58b38fa5 | ||
// which corresponds to the account[5]. | ||
new Subproviders.PrivateKeyWalletSubprovider( | ||
"f95e1da038f1fd240cb0c966d8826fb5c0369407f76f34736a5c381da7ca0ecd" | ||
) | ||
) | ||
engine.addProvider( | ||
// Local geth websocket endpoint. | ||
new WebsocketSubprovider( | ||
{rpcUrl: "ws://127.0.0.1:8546"} | ||
) | ||
) | ||
|
||
const web3 = new Web3(engine) | ||
|
||
engine.start() | ||
|
||
async function run() { | ||
// Set 0xd6b0a1ca8f0641b97efec0f1ed73d72e58b38fa5 as default account. | ||
web3.eth.defaultAccount = (await web3.eth.getAccounts())[0] | ||
|
||
const tbtc = await TBTC.withConfig({ | ||
web3: web3, | ||
bitcoinNetwork: "testnet", | ||
electrum: { | ||
testnet: { | ||
server: "10.102.100.24", | ||
port: 443, | ||
protocol: "ssl" | ||
}, | ||
testnetWS: { | ||
server: "10.102.100.24", | ||
port: 8080, | ||
protocol: "ws" | ||
} | ||
} | ||
}) | ||
|
||
|
||
const deposits = [] | ||
for (let i = 1; i <= depositsCount; i++) { | ||
console.log(`\nStarting deposit number [${i}]...\n`) | ||
const deposit = await createDeposit(tbtc, satoshiLotSize) | ||
deposits.push(deposit) | ||
console.log(`\nDeposit ${deposit.address} has been created successfully.`) | ||
} | ||
|
||
console.log(`\nStarting redemption of the first deposit...\n`) | ||
const message = await redeemDeposit(tbtc, deposits[0].address, btcAddress) | ||
console.log(`\nRedemption outcome: ${message}\n`) | ||
} | ||
|
||
async function createDeposit(tbtc, satoshiLotSize) { | ||
const deposit = await tbtc.Deposit.withSatoshiLotSize( | ||
web3.utils.toBN(satoshiLotSize) | ||
) | ||
|
||
deposit.autoSubmit() | ||
|
||
return new Promise(async (resolve, reject) => { | ||
deposit.onBitcoinAddressAvailable(async address => { | ||
try { | ||
const lotSize = await deposit.getSatoshiLotSize() | ||
console.log( | ||
"\tGot deposit address:", | ||
address, | ||
"; fund with:", | ||
lotSize.toString(), | ||
"satoshis please." | ||
) | ||
console.log("Now monitoring for deposit transaction...") | ||
} catch (err) { | ||
reject(err) | ||
} | ||
}) | ||
|
||
deposit.onActive(async () => { | ||
try { | ||
console.log("Deposit is active, minting...") | ||
await deposit.mintTBTC() | ||
resolve(deposit) | ||
} catch (err) { | ||
reject(err) | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
async function redeemDeposit(tbtc, depositAddress, redeemerAddress) { | ||
return new Promise(async (resolve, reject) => { | ||
try { | ||
const deposit = await tbtc.Deposit.withAddress(depositAddress) | ||
const redemption = await deposit.requestRedemption(redeemerAddress) | ||
redemption.autoSubmit() | ||
|
||
redemption.onWithdrawn(transactionID => { | ||
console.log() | ||
|
||
resolve( | ||
`Redeemed deposit ${deposit.address} with Bitcoin transaction ` + | ||
`${transactionID}.` | ||
) | ||
}) | ||
} catch (err) { | ||
reject(err) | ||
} | ||
}) | ||
} | ||
|
||
run() | ||
.then(result => { | ||
console.log("Test completed successfully") | ||
|
||
process.exit(0) | ||
}) | ||
.catch(error => { | ||
console.error("Test errored out with error: ", error) | ||
|
||
process.exit(1) | ||
}) |
Oops, something went wrong.