Skip to content

Commit

Permalink
Merge pull request #325 from HathorNetwork/dev
Browse files Browse the repository at this point in the history
Release 0.22.0-rc4
  • Loading branch information
r4mmer authored Aug 4, 2023
2 parents 8fe49d8 + a793c26 commit 3defcbd
Show file tree
Hide file tree
Showing 17 changed files with 2,551 additions and 45 deletions.
44 changes: 42 additions & 2 deletions __tests__/__fixtures__/http-fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,47 @@ export default {
address: 'WewDeXWyvHP7jJTs7tjLoQfoB72LLxJQqN',
timelock: 32522094000,
},
token: '03',
token: '0000073b972162f70061f61cf0082b7a47263cc1659a05976aca5cd01b3351ee',
spent_by: null,
selected_as_input: false,
},
{
value: 1,
token_data: 129,
script: 'qRTqJUJmzEmBNvhkmDuZ4JxcMh5/ioc=',
decoded: {
type: 'P2SH',
address: 'wgyUgNjqZ18uYr4YfE2ALW6tP5hd8MumH5',
timelock: null
},
token: '0000073b972162f70061f61cf0082b7a47263cc1659a05976aca5cd01b3351ee',
spent_by: null,
selected_as_input: false,
},
{
value: 200,
token_data: 1,
script: 'dqkU/qcZVmiK7oEMzDyVX9kwfldkR8CIrA==',
decoded: {
type: 'P2SH',
address: 'wgyUgNjqZ18uYr4YfE2ALW6tP5hd8MumH5',
timelock: null
},
token:
'0000073b972162f70061f61cf0082b7a47263cc1659a05976aca5cd01b3351ee',
spent_by: null,
selected_as_input: false,
},
{
value: 2,
token_data: 129,
script: 'qRTqJUJmzEmBNvhkmDuZ4JxcMh5/ioc=',
decoded: {
type: 'P2SH',
address: 'wgyUgNjqZ18uYr4YfE2ALW6tP5hd8MumH5',
timelock: null
},
token: '0000073b972162f70061f61cf0082b7a47263cc1659a05976aca5cd01b3351ee',
spent_by: null,
selected_as_input: false,
},
Expand All @@ -720,7 +760,7 @@ export default {
'00e161a6b0bee1781ea9300680913fb76fd0fac4acab527cd9626cc1514abdc9',
],
height: 19,
tokens: ['03']
tokens: ['0000073b972162f70061f61cf0082b7a47263cc1659a05976aca5cd01b3351ee']
},
{
tx_id:
Expand Down
73 changes: 67 additions & 6 deletions __tests__/decode.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PartialTx, ProposalInput, ProposalOutput } from '@hathor/wallet-lib/lib/models/partial_tx';
import { Network, Address, P2PKH } from '@hathor/wallet-lib';
import httpFixtures from './__fixtures__/http-fixtures';
import TestUtils from './test-utils';

const walletId = 'stub_decode';
Expand Down Expand Up @@ -84,10 +85,12 @@ describe('decode api', () => {
const expected = {
success: true,
tx: {
completeSignatures: false,
tokens: [],
inputs: [],
outputs: [],
}
},
balance: {},
};

let response = await TestUtils.request
Expand Down Expand Up @@ -135,7 +138,11 @@ describe('decode api', () => {
let address = new Address(TestUtils.addresses[0]);
let script = new P2PKH(address);
partialTx.outputs.push(
new ProposalOutput(10, script.createScript(), { token: fakeToken1, tokenData: 1 })
new ProposalOutput(
10,
script.createScript(),
{ token: fakeToken1, tokenData: 1 }
)
);

address = new Address(TestUtils.addresses[1]);
Expand All @@ -152,6 +159,18 @@ describe('decode api', () => {
)
);

const txHistoryResponse = httpFixtures['/thin_wallet/address_history'];
const txHistory = txHistoryResponse.history;
const fakeTx = txHistory[0];
const fakeTxResponse = {
success: true,
tx: fakeTx,
meta: {
first_block_height: 1234,
},
};
TestUtils.httpMock.onGet('/transaction').reply(200, fakeTxResponse);

// 1 input, 2 outputs
const response = await TestUtils.request
.post('/wallet/decode')
Expand All @@ -162,22 +181,64 @@ describe('decode api', () => {
expect(response.body).toEqual({
success: true,
tx: expect.objectContaining({
tokens: [fakeToken1, fakeToken2],
inputs: [{ txId: fakeInputHash, index: 1 }],
completeSignatures: false,
tokens: expect.arrayContaining([fakeToken1, fakeToken2]),
inputs: [
{
txId: fakeInputHash,
index: 1,
value: 6400,
decoded: {
address: 'wgyUgNjqZ18uYr4YfE2ALW6tP5hd8MumH5',
type: 'MultiSig',
timelock: null,
},
script: expect.any(String),
token: '00',
tokenData: 0,
token_data: 0,
mine: true,
signed: false,
},
],
outputs: [
expect.objectContaining({
value: 10,
tokenData: 1,
token_data: 1,
token: fakeToken1,
decoded: expect.objectContaining({ address: TestUtils.addresses[0] })
decoded: {
address: TestUtils.addresses[0],
timelock: null,
mine: false,
},
script: expect.any(String),
type: 'p2pkh',
}),
expect.objectContaining({
value: 20,
tokenData: 0,
decoded: expect.objectContaining({ address: TestUtils.addresses[1] })
token_data: 0,
decoded: {
address: TestUtils.addresses[1],
timelock: null,
mine: false,
},
script: expect.any(String),
token: '00',
type: 'p2pkh',
}),
],
}),
balance: {
'00': {
tokens: { available: -6400, locked: 0 },
authorities: {
melt: { available: 0, locked: 0 },
mint: { available: 0, locked: 0 },
},
},
},
});

spy.mockRestore();
Expand Down
8 changes: 4 additions & 4 deletions __tests__/integration/atomic-swap.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,10 @@ describe('send tx (HTR)', () => {
]),
}),
});
decodeResponse.body.tx.inputs.map(input => expect(input).toEqual({
decodeResponse.body.tx.inputs.map(input => expect(input).toEqual(expect.objectContaining({
txId: expect.any(String),
index: expect.any(Number),
}));
})));

expect(response.body.isComplete).toBe(false);

Expand Down Expand Up @@ -507,10 +507,10 @@ describe('send tx (HTR)', () => {
]),
},
});
decodeResponse.body.tx.inputs.map(input => expect(input).toEqual({
decodeResponse.body.tx.inputs.map(input => expect(input).toEqual(expect.objectContaining({
txId: expect.any(String),
index: expect.any(Number),
}));
})));

// wallet1: sign data
response = await TestUtils.request
Expand Down
Loading

0 comments on commit 3defcbd

Please sign in to comment.