|
| 1 | +import { |
| 2 | + getRandomInt, |
| 3 | + HATHOR_TOKEN_ID, |
| 4 | + TestUtils, |
| 5 | + WALLET_CONSTANTS |
| 6 | +} from './utils/test-utils-integration'; |
| 7 | +import { WalletHelper } from './utils/wallet-helper'; |
| 8 | + |
| 9 | +describe('address-info routes', () => { |
| 10 | + let wallet1; |
| 11 | + let wallet2; |
| 12 | + const address1balance = getRandomInt(200, 100); |
| 13 | + let customTokenHash; |
| 14 | + |
| 15 | + beforeAll(async () => { |
| 16 | + try { |
| 17 | + // A random HTR value for the first wallet |
| 18 | + wallet1 = new WalletHelper('addinfo-1'); |
| 19 | + await wallet1.start(); |
| 20 | + await wallet1.injectFunds(address1balance, 1); |
| 21 | + |
| 22 | + // A fixed custom token amount for the second wallet |
| 23 | + wallet2 = new WalletHelper('addinfo-2'); |
| 24 | + await wallet2.start(); |
| 25 | + await wallet2.injectFunds(10); |
| 26 | + const customToken = await wallet2.createToken({ |
| 27 | + amount: 500, |
| 28 | + name: 'AddInfo Token', |
| 29 | + symbol: 'AIT', |
| 30 | + address: await wallet2.getAddressAt(1), |
| 31 | + change_address: await wallet2.getAddressAt(0) |
| 32 | + }); |
| 33 | + customTokenHash = customToken.hash; |
| 34 | + |
| 35 | + /* |
| 36 | + * The state here should be: |
| 37 | + * wallet1[1] with some value between 100 and 200 HTR |
| 38 | + * wallet2[0] with 5 HTR |
| 39 | + * wallet2[1] with 500 AIT |
| 40 | + */ |
| 41 | + } catch (err) { |
| 42 | + TestUtils.logError(err.stack); |
| 43 | + } |
| 44 | + }); |
| 45 | + |
| 46 | + afterAll(async () => { |
| 47 | + await wallet1.stop(); |
| 48 | + await wallet2.stop(); |
| 49 | + }); |
| 50 | + |
| 51 | + it('should return results for an address (empty)', async done => { |
| 52 | + const response = await TestUtils.request |
| 53 | + .get('/wallet/address-info') |
| 54 | + .query({ address: await wallet1.getAddressAt(0) }) |
| 55 | + .set({ 'x-wallet-id': wallet1.walletId }); |
| 56 | + |
| 57 | + expect(response.status).toBe(200); |
| 58 | + |
| 59 | + const results = response.body; |
| 60 | + expect(results.success).toBeTruthy(); |
| 61 | + expect(results.token).toBe(HATHOR_TOKEN_ID); |
| 62 | + expect(results.index).toBe(0); |
| 63 | + expect(results.total_amount_received).toBe(0); |
| 64 | + expect(results.total_amount_sent).toBe(0); |
| 65 | + expect(results.total_amount_available).toBe(0); |
| 66 | + expect(results.total_amount_locked).toBe(0); |
| 67 | + done(); |
| 68 | + }); |
| 69 | + |
| 70 | + it('should return results for an address with a single receiving transaction', async done => { |
| 71 | + const response = await TestUtils.request |
| 72 | + .get('/wallet/address-info') |
| 73 | + .query({ address: await wallet1.getAddressAt(1) }) |
| 74 | + .set({ 'x-wallet-id': wallet1.walletId }); |
| 75 | + |
| 76 | + expect(response.status).toBe(200); |
| 77 | + |
| 78 | + const results = response.body; |
| 79 | + expect(results.success).toBeTruthy(); |
| 80 | + expect(results.token).toBe(HATHOR_TOKEN_ID); |
| 81 | + expect(results.index).toBe(1); |
| 82 | + expect(results.total_amount_received).toBe(address1balance); |
| 83 | + expect(results.total_amount_sent).toBe(0); |
| 84 | + expect(results.total_amount_available).toBe(address1balance); |
| 85 | + expect(results.total_amount_locked).toBe(0); |
| 86 | + done(); |
| 87 | + }); |
| 88 | + |
| 89 | + it('should return correct locked balance for an address with miner rewards', async done => { |
| 90 | + const response = await TestUtils.request |
| 91 | + .get('/wallet/address-info') |
| 92 | + .query({ address: WALLET_CONSTANTS.genesis.addresses[1] }) // Miner rewards address |
| 93 | + .set({ 'x-wallet-id': WALLET_CONSTANTS.genesis.walletId }); |
| 94 | + |
| 95 | + expect(response.status).toBe(200); |
| 96 | + |
| 97 | + const results = response.body; |
| 98 | + expect(results.success).toBeTruthy(); |
| 99 | + expect(results.token).toBe(HATHOR_TOKEN_ID); |
| 100 | + expect(results.index).toBe(2); |
| 101 | + expect(results.total_amount_received).toBeGreaterThan(0); |
| 102 | + |
| 103 | + /* |
| 104 | + * According to the REWARD_SPEND_MIN_BLOCKS variable in the ./configuration/privnet.py file |
| 105 | + * the miner rewards are locked for exactly one block. Since we have only one miner reward |
| 106 | + * address, this value should be always 6400 or greater. |
| 107 | + * |
| 108 | + * Should another miner reward address be included later, this assertion must be recalculated. |
| 109 | + */ |
| 110 | + expect(results.total_amount_locked).toBeGreaterThanOrEqual(6400); |
| 111 | + done(); |
| 112 | + }); |
| 113 | + |
| 114 | + it('should return results for an address with send/receive transactions', async done => { |
| 115 | + const response = await TestUtils.request |
| 116 | + .get('/wallet/address-info') |
| 117 | + .query({ address: await wallet2.getAddressAt(0) }) |
| 118 | + .set({ 'x-wallet-id': wallet2.walletId }); |
| 119 | + |
| 120 | + expect(response.status).toBe(200); |
| 121 | + |
| 122 | + const results = response.body; |
| 123 | + expect(results.success).toBeTruthy(); |
| 124 | + expect(results.token).toBe(HATHOR_TOKEN_ID); |
| 125 | + expect(results.index).toBe(0); |
| 126 | + expect(results.total_amount_received).toBe(15); // 10 from genesis, 5 from token creation change |
| 127 | + expect(results.total_amount_sent).toBe(10); // token creation tx |
| 128 | + expect(results.total_amount_available).toBe(5); // change |
| 129 | + expect(results.total_amount_locked).toBe(0); |
| 130 | + done(); |
| 131 | + }); |
| 132 | + |
| 133 | + it('should return results for custom token for an address (empty)', async done => { |
| 134 | + const response = await TestUtils.request |
| 135 | + .get('/wallet/address-info') |
| 136 | + .query({ |
| 137 | + address: await wallet2.getAddressAt(0), |
| 138 | + token: customTokenHash, |
| 139 | + }) |
| 140 | + .set({ 'x-wallet-id': wallet2.walletId }); |
| 141 | + |
| 142 | + expect(response.status).toBe(200); |
| 143 | + |
| 144 | + const results = response.body; |
| 145 | + expect(results.success).toBeTruthy(); |
| 146 | + expect(results.token).toBe(customTokenHash); |
| 147 | + expect(results.index).toBe(0); |
| 148 | + expect(results.total_amount_received).toBe(0); |
| 149 | + expect(results.total_amount_sent).toBe(0); |
| 150 | + expect(results.total_amount_available).toBe(0); |
| 151 | + expect(results.total_amount_locked).toBe(0); |
| 152 | + done(); |
| 153 | + }); |
| 154 | + |
| 155 | + it('should return results for custom token on an address with a single transaction', async done => { |
| 156 | + const response = await TestUtils.request |
| 157 | + .get('/wallet/address-info') |
| 158 | + .query({ |
| 159 | + address: await wallet2.getAddressAt(1), |
| 160 | + token: customTokenHash, |
| 161 | + }) |
| 162 | + .set({ 'x-wallet-id': wallet2.walletId }); |
| 163 | + |
| 164 | + expect(response.status).toBe(200); |
| 165 | + |
| 166 | + const results = response.body; |
| 167 | + expect(results.success).toBeTruthy(); |
| 168 | + expect(results.token).toBe(customTokenHash); |
| 169 | + expect(results.index).toBe(1); |
| 170 | + expect(results.total_amount_received).toBe(500); |
| 171 | + expect(results.total_amount_sent).toBe(0); |
| 172 | + expect(results.total_amount_available).toBe(500); |
| 173 | + expect(results.total_amount_locked).toBe(0); |
| 174 | + done(); |
| 175 | + }); |
| 176 | +}); |
0 commit comments