-
Notifications
You must be signed in to change notification settings - Fork 25
Integration tests: simple send-tx, send-tx, create-tokens, mint and melt tokens #152
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
Merged
Merged
Changes from 20 commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
02d0029
docs: minor changes to jsdocs
tuliomir 7d537a9
perf: wallets starting in parallel instead of serially
tuliomir 1dcdcc9
feat: simple-send-tx tests
tuliomir 02bc015
feat: send-tx tests with single token and automatic inputs
tuliomir 1a35e44
refactor: logging address samples when starting multiple wallets
tuliomir 5dc8a4e
test: sending with filter_address query
tuliomir 894b571
test: sending with single input
tuliomir 9db6c4b
test: sending with multiple inputs
tuliomir f5a45b8
test: sending a custom token
tuliomir 18e0e1c
test: sending custom tokens with inputs and "body.token" property
tuliomir 98acaac
test: send-tx with multiple tokens
tuliomir 1900c38
refactor: successful transactions changed to use wallet helper
tuliomir a0a17df
style: applied standardized formatting
tuliomir d27fed8
test: create-token tests
tuliomir 69e7b4e
test: mint-token tests
tuliomir 9416f88
test: melt-tokens tests
tuliomir cd5deda
refactor: improving docs and naming for clarity
tuliomir 345132f
style: linting
tuliomir 7df12d8
style: fix wrong linting of expect calls
tuliomir f493395
docs: minor fixes to comments and jsdocs
tuliomir 4f0f1dd
refactor: wallet validation pooling off by default
tuliomir ce9a797
perf: transactions no longer pause to wait for websocket response
tuliomir a0ddc14
docs: jsdocs, comments and variable renaming
tuliomir 0af0a34
feat: new helper functions for wallet txHistory and balance
tuliomir cf50d7b
refactor: improvements to create-token legibility
tuliomir aa62ed6
test: testing all input possibilities on create-token
tuliomir 4bfbc4e
test: testing all input possibilities on mint-tokens
tuliomir ff5a026
test: improving assertions and validations on simple-send-tx
tuliomir 2ae9839
test: improving assertions and validations on melt-tokens
tuliomir 10260cd
test: improving assertions and validations on send-tx
tuliomir 1846a50
test: multi-token, automatic change address test
tuliomir 19eb84f
style: eslint
tuliomir d9f3e4c
test: create-token field size validations
tuliomir bca626b
test: new token api tests with a single input and with no inputs
tuliomir 00118d6
refactor: renaming variables for clarity
tuliomir be1868a
fix: made tests more strict and skipped failing ones
tuliomir 5ed963b
fix: removing unnecessary tests and assertions
tuliomir b796bbc
test: including assertion for change address on basic create token test
tuliomir 81e7435
style: converted static string templates into single tick strings
tuliomir 5d96d3d
perf: wallet starter now working in parallel
tuliomir f03d567
refactor: removed irrelevant afterAll() on setupTests-integration
tuliomir 48b06dd
style: typo
tuliomir 6125d91
refactor: websocket update delay period moved to config file
tuliomir bf92183
feat: timeout protection on multiple wallet initialization.
tuliomir 0a8246f
chore: added new timeout variable to config files
tuliomir 126370d
docs: added todos on pending assertions
tuliomir 02d690b
chore: moved test configurations to separate file
tuliomir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -5,5 +5,6 @@ config.js | |
node_modules/ | ||
|
||
coverage | ||
coverage-integration | ||
|
||
.DS_Store |
This file contains hidden or 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 hidden or 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 hidden or 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,172 @@ | ||
import { getRandomInt, TestUtils } from './utils/test-utils-integration'; | ||
import { WalletHelper } from './utils/wallet-helper'; | ||
|
||
describe('create token', () => { | ||
let wallet1; | ||
let wallet2; | ||
|
||
const fundTx1 = { | ||
hash: null, | ||
index: null | ||
}; | ||
const fundTx2 = { | ||
hash: null, | ||
index: null | ||
}; | ||
|
||
const tokenA = { | ||
name: 'Token A', | ||
symbol: 'TKA', | ||
uid: null | ||
}; | ||
const tokenB = { | ||
name: 'Token B', | ||
symbol: 'TKB', | ||
uid: null | ||
}; | ||
|
||
beforeAll(async () => { | ||
wallet1 = new WalletHelper('create-token-1'); | ||
wallet2 = new WalletHelper('create-token-2'); | ||
|
||
await WalletHelper.startMultipleWalletsForTest([wallet1, wallet2]); | ||
const fundTxObj1 = await wallet1.injectFunds(10, 0, { doNotWait: true }); | ||
fundTx1.hash = fundTxObj1.hash; | ||
fundTx1.index = TestUtils.getOutputIndexFromTx(fundTxObj1, 10); | ||
|
||
const fundTxObj2 = await wallet1.injectFunds(10, 1, { doNotWait: true }); | ||
fundTx2.hash = fundTxObj2.hash; | ||
fundTx2.index = TestUtils.getOutputIndexFromTx(fundTxObj2, 10); | ||
|
||
await wallet2.injectFunds(10, 0, { doNotWait: true }); | ||
await TestUtils.delay(1000); | ||
}); | ||
|
||
afterAll(async () => { | ||
await wallet1.stop(); | ||
}); | ||
|
||
// Testing failures first, that do not cause side-effects on the blockchain | ||
|
||
it('should reject missing name parameter', async done => { | ||
const response = await TestUtils.request | ||
.post('/wallet/create-token') | ||
.send({ | ||
symbol: tokenA.symbol, | ||
amount: 1000 | ||
}) | ||
.set({ 'x-wallet-id': wallet1.walletId }); | ||
|
||
expect(response.status).toBe(400); | ||
expect(response.body.success).toBe(false); | ||
done(); | ||
}); | ||
|
||
it('should reject missing symbol parameter', async done => { | ||
const response = await TestUtils.request | ||
.post('/wallet/create-token') | ||
.send({ | ||
name: tokenA.name, | ||
amount: 1000 | ||
}) | ||
.set({ 'x-wallet-id': wallet1.walletId }); | ||
|
||
expect(response.status).toBe(400); | ||
expect(response.body.success).toBe(false); | ||
done(); | ||
}); | ||
|
||
// Insuficcient funds | ||
|
||
it('should reject for insuficcient funds', async done => { | ||
const response = await TestUtils.request | ||
.post('/wallet/create-token') | ||
.send({ | ||
name: tokenA.name, | ||
symbol: tokenA.symbol, | ||
amount: 3000 | ||
}) | ||
.set({ 'x-wallet-id': wallet1.walletId }); | ||
|
||
expect(response.status).toBe(200); | ||
expect(response.body.success).toBe(false); | ||
expect(response.body.hash).toBeUndefined(); | ||
done(); | ||
}); | ||
|
||
it('should not create a token with the reserved HTR symbol', async done => { | ||
const response = await TestUtils.request | ||
.post('/wallet/create-token') | ||
.send({ | ||
name: 'Hathor', | ||
symbol: 'HTR', | ||
amount: 100 | ||
}) | ||
.set({ 'x-wallet-id': wallet1.walletId }); | ||
|
||
expect(response.status).toBe(200); | ||
expect(response.body.success).toBe(false); | ||
expect(response.body.hash).toBeUndefined(); | ||
expect(response.body.error).toContain('Invalid token name'); | ||
done(); | ||
}); | ||
|
||
it('should create a token successfully', async done => { | ||
const response = await TestUtils.request | ||
.post('/wallet/create-token') | ||
.send({ | ||
name: tokenA.name, | ||
symbol: tokenA.symbol, | ||
amount: 100 | ||
}) | ||
.set({ 'x-wallet-id': wallet1.walletId }); | ||
|
||
pedroferreira1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expect(response.body.success).toBe(true); | ||
expect(response.body.hash).toBeDefined(); | ||
done(); | ||
}); | ||
|
||
it('should send the created tokens to the correct address', async done => { | ||
const amountTokens = getRandomInt(100, 200); | ||
const response = await TestUtils.request | ||
.post('/wallet/create-token') | ||
.send({ | ||
name: tokenB.name, | ||
symbol: tokenB.symbol, | ||
amount: amountTokens, | ||
address: await wallet1.getAddressAt(9) | ||
}) | ||
.set({ 'x-wallet-id': wallet1.walletId }); | ||
|
||
const transaction = response.body; | ||
expect(transaction.success).toBe(true); | ||
|
||
const addr8 = await wallet1.getAddressInfo(9, transaction.hash); | ||
expect(addr8.total_amount_received).toBe(amountTokens); | ||
done(); | ||
}); | ||
|
||
it('should send the change to the correct address', async done => { | ||
const response = await TestUtils.request | ||
.post('/wallet/create-token') | ||
.send({ | ||
name: tokenB.name, | ||
symbol: tokenB.symbol, | ||
amount: 100, | ||
change_address: await wallet2.getAddressAt(5) | ||
}) | ||
.set({ 'x-wallet-id': wallet2.walletId }); | ||
|
||
const transaction = response.body; | ||
expect(transaction.success).toBe(true); | ||
const customTokenOutputIndex = TestUtils.getOutputIndexFromTx(transaction, 100); | ||
|
||
// If the custom token output is 0, the HTR will be on the output index 1. And vice-versa. | ||
pedroferreira1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const htrOutputIndex = customTokenOutputIndex === 1 ? 0 : 1; | ||
const htrChange = transaction.outputs[htrOutputIndex].value; | ||
|
||
const addr8 = await wallet1.getAddressInfo(5); | ||
expect(addr8.total_amount_received).toBe(htrChange); | ||
done(); | ||
}); | ||
}); |
This file contains hidden or 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 hidden or 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,122 @@ | ||
import { TestUtils } from './utils/test-utils-integration'; | ||
import { WalletHelper } from './utils/wallet-helper'; | ||
|
||
describe('melt tokens', () => { | ||
let wallet1; | ||
const tokenA = { | ||
name: 'Token A', | ||
symbol: 'TKA', | ||
uid: null | ||
}; | ||
|
||
beforeAll(async () => { | ||
wallet1 = new WalletHelper('melt-token-1'); | ||
|
||
// Starting the wallets | ||
await WalletHelper.startMultipleWalletsForTest([wallet1]); | ||
|
||
// Creating a token for the tests | ||
await wallet1.injectFunds(10, 0, { doNotWait: true }); | ||
const tkAtx = await wallet1.createToken({ | ||
name: tokenA.name, | ||
symbol: tokenA.symbol, | ||
amount: 800, | ||
address: await wallet1.getAddressAt(0), | ||
change_address: await wallet1.getAddressAt(0) | ||
}); | ||
tokenA.uid = tkAtx.hash; | ||
}); | ||
|
||
afterAll(async () => { | ||
await wallet1.stop(); | ||
}); | ||
|
||
// Testing failures first, that do not cause side-effects on the blockchain | ||
|
||
it('should not melt an invalid token', async done => { | ||
const response = await TestUtils.request | ||
.post('/wallet/melt-tokens') | ||
.send({ | ||
token: 'invalidToken', | ||
amount: 100 | ||
}) | ||
.set({ 'x-wallet-id': wallet1.walletId }); | ||
|
||
expect(response.status).toBe(200); | ||
expect(response.body.success).toBe(false); | ||
|
||
// Even though the result is correct, the error thrown is not related. Should be fixed later. | ||
andreabadesso marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// expect(response.body.error).toContain('invalid'); | ||
done(); | ||
}); | ||
|
||
it('should not melt with an invalid amount', async done => { | ||
const response = await TestUtils.request | ||
.post('/wallet/melt-tokens') | ||
.send({ | ||
token: tokenA.uid, | ||
amount: 'invalidVamount' | ||
}) | ||
.set({ 'x-wallet-id': wallet1.walletId }); | ||
|
||
expect(response.status).toBe(400); | ||
expect(response.body.success).toBe(false); | ||
expect(response.text).toContain('invalid'); | ||
done(); | ||
}); | ||
|
||
// Insufficient funds | ||
|
||
it('should not melt with insuficcient tokens', async done => { | ||
const response = await TestUtils.request | ||
.post('/wallet/melt-tokens') | ||
.send({ | ||
token: tokenA.uid, | ||
address: await wallet1.getAddressAt(1), | ||
amount: 1000 | ||
}) | ||
.set({ 'x-wallet-id': wallet1.walletId }); | ||
|
||
expect(response.status).toBe(200); | ||
expect(response.body.success).toBe(false); | ||
expect(response.body.error).toContain('enough inputs to melt'); | ||
done(); | ||
}); | ||
|
||
// Success | ||
|
||
it('should melt with correct parameters', async done => { | ||
const response = await TestUtils.request | ||
.post('/wallet/melt-tokens') | ||
.send({ | ||
token: tokenA.uid, | ||
address: await wallet1.getAddressAt(1), | ||
amount: 300 | ||
}) | ||
.set({ 'x-wallet-id': wallet1.walletId }); | ||
|
||
expect(response.body.success).toBe(true); | ||
done(); | ||
}); | ||
|
||
it('should melt all the tokens', async done => { | ||
const response = await TestUtils.request | ||
.post('/wallet/melt-tokens') | ||
.send({ | ||
token: tokenA.uid, | ||
address: await wallet1.getAddressAt(1), | ||
pedroferreira1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
amount: 500 | ||
}) | ||
.set({ 'x-wallet-id': wallet1.walletId }); | ||
|
||
expect(response.body.success).toBe(true); | ||
|
||
const balanceResult = await TestUtils.request | ||
.get('/wallet/balance') | ||
.query({ token: tokenA.uid }) | ||
.set({ 'x-wallet-id': wallet1.walletId }); | ||
|
||
expect(balanceResult.body.available).toBe(0); | ||
done(); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.