-
Notifications
You must be signed in to change notification settings - Fork 32
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 #80 from Bitcoin-com/stage
fix(tokenUtxoDetails): support mint token transactions
- Loading branch information
Showing
9 changed files
with
412 additions
and
18 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
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,102 @@ | ||
/* | ||
This is an end-to-end test which verified the happy-path of sending an SLP | ||
token. It's really a test of the speed of SLPDB to process new token | ||
transactions. | ||
This program expects two wallets. Wallet 1 must have a small amount of BCH | ||
and an inventory of SLP test tokens. Wallet 2 is the reieving wallet. | ||
*/ | ||
|
||
// Inspect utility used for debugging. | ||
const util = require("util") | ||
util.inspect.defaultOptions = { | ||
showHidden: true, | ||
colors: true, | ||
depth: 1 | ||
} | ||
|
||
// const SLPSDK = require("../../../lib/SLP") | ||
// const slpsdk = new SLPSDK() | ||
|
||
const WALLET1 = `../wallet1.json` | ||
const WALLET2 = `../wallet2.json` | ||
|
||
const lib = require("../util/e2e-util") | ||
|
||
// The main test function. | ||
// Sends a token and reports on how long it takes to show up in SLPDB production. | ||
async function sendTokenTest() { | ||
try { | ||
// Open the sending wallet. | ||
const sendWallet = await lib.openWallet(WALLET1) | ||
//console.log(`sendWallet: ${JSON.stringify(walletInfo, null, 2)}`) | ||
|
||
// Open the recieving wallet. | ||
const recvWallet = await lib.openWallet(WALLET2) | ||
//console.log(`recvWallet: ${JSON.stringify(walletInfo, null, 2)}`) | ||
|
||
// Get the balance of the recieving wallet. | ||
// const testTokens = recvWallet.tokenBalance.filter( | ||
// x => testTokenId === x.tokenId | ||
// ) | ||
// const startBalance = testTokens[0].balance | ||
const startBalance = await lib.getTestTokenBalance(recvWallet) | ||
console.log(`Starting balance: ${startBalance} test tokens.`) | ||
let newBalance = startBalance | ||
|
||
// Send a token to the recieving wallet. | ||
await lib.sendToken(sendWallet, recvWallet) | ||
console.log(`Sent test token.`) | ||
|
||
// Track the time until the balance for the recieving wallet has been updated. | ||
const startTime = new Date() | ||
const waitTime = 10000 // time in milliseconds | ||
|
||
// Loop with a definite exit point, so we don't loop forever. | ||
for (let i = 0; i < 50; i++) { | ||
await sleep(waitTime) // Wait for a while before checking | ||
|
||
console.log(`Checking token balance...`) | ||
newBalance = await lib.getTestTokenBalance(recvWallet) | ||
|
||
// Break out of the loop once a new balance is detected. | ||
if (newBalance > startBalance) break | ||
|
||
// Provide high-level warnings. | ||
const secondsPassed = (i * waitTime) / 1000 | ||
if (secondsPassed > 60 * 10) { | ||
console.log(`More than 10 minutes passed.`) | ||
return false // Fail the test. | ||
} else if (secondsPassed > 60 * 5) { | ||
console.log(`More than 5 minutes passed.`) | ||
} else if (secondsPassed > 60) { | ||
console.log(`More than 1 minute passed.`) | ||
} | ||
} | ||
|
||
// Calculate the amount of time that has passed. | ||
const endTime = new Date() | ||
let deltaTime = (endTime.getTime() - startTime.getTime()) / 60000 | ||
deltaTime = lib.threeDecimals(deltaTime) | ||
console.log(`SLPDB updated token balance in ${deltaTime} minutes.`) | ||
|
||
// Consolidate the SLP UTXOs on the recieve wallet. | ||
// CT 9/11/19: This causes the test to fail if done every time. This will | ||
// have to be done manually. | ||
//await lib.sendToken(recvWallet, recvWallet) | ||
|
||
return deltaTime // Return the time in minutes it took for SLPDB to update. | ||
} catch (err) { | ||
console.log(`Error in e2e/send-token.js/sendTokenTest(): `, err) | ||
return false | ||
} | ||
} | ||
|
||
// Promise based sleep function. | ||
function sleep(ms) { | ||
return new Promise(resolve => setTimeout(resolve, ms)) | ||
} | ||
|
||
module.exports = { | ||
sendTokenTest | ||
} |
Oops, something went wrong.