-
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 34 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,290 @@ | ||
import { getRandomInt, TestUtils, WALLET_CONSTANTS } from './utils/test-utils-integration'; | ||
import { WalletHelper } from './utils/wallet-helper'; | ||
|
||
describe('create token', () => { | ||
let wallet1; | ||
let wallet2; | ||
|
||
const tokenA = { | ||
name: 'Token A', | ||
symbol: 'TKA', | ||
uid: null | ||
}; | ||
|
||
beforeAll(async () => { | ||
wallet1 = new WalletHelper('create-token-1'); | ||
wallet2 = new WalletHelper('create-token-2'); | ||
|
||
await WalletHelper.startMultipleWalletsForTest([wallet1, wallet2]); | ||
await wallet1.injectFunds(10, 0); | ||
await wallet1.injectFunds(10, 1); | ||
await wallet2.injectFunds(10, 0); | ||
}); | ||
|
||
afterAll(async () => { | ||
await wallet1.stop(); | ||
await wallet2.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(); | ||
}); | ||
|
||
it('should reject a name with more than 30 characters', async done => { | ||
const response = await TestUtils.request | ||
.post('/wallet/create-token') | ||
.send({ | ||
name: 'Name input with more than 30 characters', | ||
symbol: tokenA.symbol, | ||
amount: 1000 | ||
}) | ||
.set({ 'x-wallet-id': wallet1.walletId }); | ||
|
||
expect(response.body.success).toBe(false); | ||
expect(response.body.error).toContain('maximum size'); | ||
done(); | ||
}); | ||
|
||
// The result is an error with the message "maximum size", but consumes the funds. Must be fixed. | ||
it.skip('should reject a symbol with more than 5 characters', async done => { | ||
const response = await TestUtils.request | ||
.post('/wallet/create-token') | ||
.send({ | ||
name: tokenA.name, | ||
symbol: 'TKABCD', | ||
amount: 1000 | ||
}) | ||
.set({ 'x-wallet-id': wallet1.walletId }); | ||
|
||
expect(response.body.success).toBe(false); | ||
expect(response.body.error).toContain('maximum size'); | ||
done(); | ||
}); | ||
|
||
it('should reject an invalid destination address', async done => { | ||
const response = await TestUtils.request | ||
.post('/wallet/create-token') | ||
.send({ | ||
name: tokenA.name, | ||
symbol: tokenA.symbol, | ||
amount: 1000, | ||
address: 'invalidAddress' | ||
}) | ||
.set({ 'x-wallet-id': wallet1.walletId }); | ||
|
||
expect(response.status).toBe(200); | ||
expect(response.body.success).toBe(false); | ||
expect(response.body.error).toContain('base58'); | ||
done(); | ||
}); | ||
|
||
it('should reject an invalid change address', async done => { | ||
const response = await TestUtils.request | ||
.post('/wallet/create-token') | ||
.send({ | ||
name: tokenA.name, | ||
symbol: tokenA.symbol, | ||
amount: 500, | ||
address: await wallet1.getAddressAt(0), | ||
change_address: 'invalidAddress' | ||
}) | ||
.set({ 'x-wallet-id': wallet1.walletId }); | ||
|
||
expect(response.status).toBe(200); | ||
expect(response.body.success).toBe(false); | ||
expect(response.body.error).toContain('Change address'); | ||
done(); | ||
}); | ||
|
||
// The application is incorrectly allowing to create a token for an outside address. | ||
it.skip('should reject creating token for address not in the wallet', async done => { | ||
pedroferreira1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const response = await TestUtils.request | ||
.post('/wallet/create-token') | ||
.send({ | ||
name: tokenA.name, | ||
symbol: tokenA.symbol, | ||
amount: 500, | ||
address: WALLET_CONSTANTS.genesis.addresses[3] | ||
}) | ||
.set({ 'x-wallet-id': wallet1.walletId }); | ||
|
||
expect(response.status).toBe(200); | ||
expect(response.body.success).toBe(false); | ||
done(); | ||
}); | ||
|
||
// The application is incorrectly allowing external addresses to receive the change | ||
pedroferreira1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
it.skip('should reject creating token for change address not in the wallet', async done => { | ||
const response = await TestUtils.request | ||
.post('/wallet/create-token') | ||
.send({ | ||
name: tokenA.name, | ||
symbol: tokenA.symbol, | ||
amount: 500, | ||
address: await wallet1.getAddressAt(0), | ||
change_address: WALLET_CONSTANTS.genesis.addresses[3] | ||
}) | ||
.set({ 'x-wallet-id': wallet1.walletId }); | ||
|
||
expect(response.status).toBe(200); | ||
expect(response.body.success).toBe(false); | ||
expect(response.text).toContain('wallet'); | ||
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 => { | ||
pedroferreira1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 with only required parameters', 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(); | ||
|
||
await TestUtils.pauseForWsUpdate(); | ||
|
||
const tkaBalance = await wallet1.getBalance(response.body.hash); | ||
expect(tkaBalance.available).toBe(100); | ||
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: 'Token B', | ||
symbol: 'TKB', | ||
amount: amountTokens, | ||
address: await wallet1.getAddressAt(9) | ||
}) | ||
.set({ 'x-wallet-id': wallet1.walletId }); | ||
|
||
const transaction = response.body; | ||
expect(transaction.success).toBe(true); | ||
|
||
await TestUtils.pauseForWsUpdate(); | ||
|
||
const addr9 = await wallet1.getAddressInfo(9, transaction.hash); | ||
expect(addr9.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: 'Token C', | ||
symbol: 'TKC', | ||
amount: 100, | ||
change_address: await wallet2.getAddressAt(5) | ||
}) | ||
.set({ 'x-wallet-id': wallet2.walletId }); | ||
|
||
const transaction = response.body; | ||
expect(transaction.success).toBe(true); | ||
|
||
// The only output with token_data equals zero is the one containing the HTR change | ||
const htrOutputIndex = transaction.outputs.findIndex(o => o.token_data === 0); | ||
const htrChange = transaction.outputs[htrOutputIndex].value; | ||
|
||
await TestUtils.pauseForWsUpdate(); | ||
|
||
const addr5 = await wallet2.getAddressInfo(5); | ||
expect(addr5.total_amount_received).toBe(htrChange); | ||
done(); | ||
}); | ||
|
||
it('should create a token with all available inputs', async done => { | ||
const response = await TestUtils.request | ||
.post('/wallet/create-token') | ||
.send({ | ||
name: 'Token D', | ||
symbol: 'TKD', | ||
amount: 200, | ||
address: await wallet2.getAddressAt(4), | ||
change_address: await wallet2.getAddressAt(4) | ||
}) | ||
.set({ 'x-wallet-id': wallet2.walletId }); | ||
|
||
const transaction = response.body; | ||
expect(transaction.success).toBe(true); | ||
|
||
// The only output with token_data equals zero is the one containing the HTR change | ||
const htrOutputIndex = transaction.outputs.findIndex(o => o.token_data === 0); | ||
const htrChange = transaction.outputs[htrOutputIndex].value; | ||
|
||
await TestUtils.pauseForWsUpdate(); | ||
|
||
const addr4 = await wallet2.getAddressInfo(4); | ||
expect(addr4.total_amount_received).toBe(htrChange); | ||
const addr4C = await wallet2.getAddressInfo(4, transaction.hash); | ||
expect(addr4C.total_amount_available).toBe(200); | ||
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
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.