Skip to content

Commit fa17c95

Browse files
Merge pull request #651 from HathorNetwork/release-candidate
release: v1.5.0
2 parents 400c319 + 8e46117 commit fa17c95

25 files changed

+9461
-7607
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
### Acceptance Criteria
2-
- Include here all things that this PR should solve
1+
# Choose a pull request template
32

4-
5-
### Security Checklist
6-
- [ ] Make sure you do not include new dependencies in the project unless strictly necessary and do not include dev-dependencies as production ones. More dependencies increase the possibility of one of them being hijacked and affecting us.
3+
- [feature PR](?template=feature.md&quick_pull=1)
4+
- [Release process](https://github.com/HathorNetwork/hathor-wallet-lib/compare/release...master?template=release.md&quick_pull=1)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
### Acceptance Criteria
2+
- Include here all things that this PR should solve
3+
4+
5+
### Security Checklist
6+
- [ ] Make sure you do not include new dependencies in the project unless strictly necessary and do not include dev-dependencies as production ones. More dependencies increase the possibility of one of them being hijacked and affecting us.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
[//]: # (This should be discussed in the daily meeting)
3+
[//]: # (Remember to bump the version to the release version after this is merged)
4+
[//]: # (Remember to communicate the release version on Slack after the bump)
5+
6+
### Description
7+
8+
Start the release process for version `X.X.X`.
9+
This PR will merge any changes on `master` into `release` branch.

.github/workflows/integration-test.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@ name: integration-test
22
on:
33
pull_request:
44
branches:
5-
- dev
5+
- release
6+
- release-candidate
67
- master
78

89
env:
910
TEST_WALLET_START_TIMEOUT: '180000' # 3 minutes
1011

1112
jobs:
1213
itest:
13-
runs-on: ubuntu-20.04
14+
runs-on: 'ubuntu-latest'
1415
timeout-minutes: 40
1516

1617
strategy:
1718
matrix:
18-
node-version: [14.x, 16.x]
19+
node-version: [20.x]
1920

2021
steps:
2122
# https://github.com/actions/checkout/releases/tag/v3.5.0
@@ -41,11 +42,10 @@ jobs:
4142
name: test-transacion-logs
4243
path: tmp
4344
- name: Upload coverage
44-
# https://github.com/codecov/codecov-action/releases/tag/v3.1.1
45-
uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70
46-
if: ${{ matrix.node-version }} == 14.x
47-
with:
48-
verbose: true
45+
# https://github.com/codecov/codecov-action/releases/tag/v4.3.0
46+
uses: codecov/codecov-action@84508663e988701840491b86de86b666e8a86bed
47+
env:
48+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
4949
- name: Collect docker logs on failure
5050
if: failure()
5151
# https://github.com/jwalton/gh-docker-logs/releases/tag/v2.2.1

.github/workflows/main.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@ on:
33
push:
44
branches:
55
- master
6-
- dev
6+
- release
7+
- release-candidate
78
tags:
89
- v*
910
pull_request:
1011
branches:
11-
- dev
12+
- release
13+
- release-candidate
1214
- master
1315
jobs:
1416
test:
1517
runs-on: 'ubuntu-latest'
1618
timeout-minutes: 40 # default is 360
1719
strategy:
1820
matrix:
19-
node-version: [12.x, 14.x]
21+
node-version: [20.x]
2022
steps:
2123
# https://github.com/actions/checkout/releases/tag/v3.5.0
2224
- uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3
@@ -32,8 +34,7 @@ jobs:
3234
- name: Test
3335
run: npm run test
3436
- name: Upload coverage
35-
# https://github.com/codecov/codecov-action/releases/tag/v3.1.1
36-
uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70
37-
if: ${{ matrix.node-version }} == 14.x
38-
with:
39-
verbose: true
37+
# https://github.com/codecov/codecov-action/releases/tag/v4.3.0
38+
uses: codecov/codecov-action@84508663e988701840491b86de86b666e8a86bed
39+
env:
40+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v14
1+
v20

CustomEnvironment.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* Copyright (c) Hathor Labs and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import * as path from 'path';
9+
10+
// eslint-disable-next-line import/no-extraneous-dependencies
11+
const NodeEnvironment = require('jest-environment-node').TestEnvironment;
12+
13+
/**
14+
* Extracts the test name from an absolute path received by the context
15+
* @param {string} filePath Absolute path
16+
* @returns {string} Test filename without directories, test suffixes or extensions
17+
* @example
18+
* const name = getTestName('/home/user/code/address-info.test.js')
19+
* assert(name == 'address-info')
20+
*/
21+
function getTestName(filePath) {
22+
const baseName = path.basename(filePath);
23+
const extName = path.extname(filePath);
24+
25+
return baseName.replace(`.test${extName}`, '');
26+
}
27+
28+
/**
29+
* This custom environment based on the Node environment is used to obtain the test name that is
30+
* currently being executed, an important piece of information used on `setupTests-integration.js`.
31+
* @see https://jestjs.io/docs/configuration#testenvironment-string
32+
*/
33+
export default class CustomEnvironment extends NodeEnvironment {
34+
/**
35+
* The testname is obtained from the constructor context
36+
* @param config
37+
* @param context
38+
*/
39+
constructor(config, context) {
40+
super(config, context);
41+
this.testName = getTestName(context.testPath);
42+
}
43+
44+
/**
45+
* The local testname is injected on the global environment for this specific test on setup
46+
* @returns {Promise<void>}
47+
*/
48+
async setup() {
49+
await super.setup();
50+
this.global.testName = this.testName;
51+
}
52+
53+
/*
54+
* For debugging purposes, some helper methods can be added to this class, such as:
55+
* - getVmContext()
56+
* - teardown()
57+
* - runScript(script)
58+
* - handleTestEvent(event)
59+
*
60+
* @see https://jestjs.io/docs/configuration#testenvironment-string
61+
*/
62+
}

__tests__/integration/nanocontracts/bet.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@ describe('full cycle of bet nano contract', () => {
301301
for (const tx of ncHistory2.history) {
302302
expect(txIds).toContain(tx.hash);
303303
}
304+
305+
// Get tx history with success
306+
const txHistory = await wallet.getTxHistory();
307+
expect(txHistory).toHaveLength(4);
304308
}
305309

306310
it('bet deposit', async () => {
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
/**
2+
* Copyright (c) Hathor Labs and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
import Serializer from '../../src/nano_contracts/serializer';
9+
import Deserializer from '../../src/nano_contracts/deserializer';
10+
11+
12+
test('Bool', () => {
13+
const serializer = new Serializer();
14+
const deserializer = new Deserializer();
15+
16+
const valueFalse = false;
17+
const serializedFalse = serializer.serializeFromType(valueFalse, 'bool');
18+
const deserializedFalse = deserializer.deserializeFromType(serializedFalse, 'bool');
19+
expect(deserializedFalse).toBe(valueFalse);
20+
21+
const valueTrue = true;
22+
const serializedTrue = serializer.serializeFromType(valueTrue, 'bool');
23+
const deserializedTrue = deserializer.deserializeFromType(serializedTrue, 'bool');
24+
expect(deserializedTrue).toBe(valueTrue);
25+
})
26+
27+
test('String', () => {
28+
const serializer = new Serializer();
29+
const deserializer = new Deserializer();
30+
31+
const value = 'test';
32+
const serialized = serializer.serializeFromType(value, 'str');
33+
const deserialized = deserializer.deserializeFromType(serialized, 'str');
34+
35+
expect(value).toBe(deserialized);
36+
})
37+
38+
test('Int', () => {
39+
const serializer = new Serializer();
40+
const deserializer = new Deserializer();
41+
42+
const value = 300;
43+
const serialized = serializer.serializeFromType(value, 'int');
44+
const deserialized = deserializer.deserializeFromType(serialized, 'int');
45+
46+
expect(value).toBe(deserialized);
47+
})
48+
49+
test('Bytes', () => {
50+
const serializer = new Serializer();
51+
const deserializer = new Deserializer();
52+
53+
const value = Buffer.from([0x74, 0x65, 0x73, 0x74]);
54+
const serialized = serializer.serializeFromType(value, 'bytes');
55+
const deserialized = deserializer.deserializeFromType(serialized, 'bytes');
56+
57+
expect(value.equals(deserialized)).toBe(true);
58+
})
59+
60+
test('Float', () => {
61+
const serializer = new Serializer();
62+
const deserializer = new Deserializer();
63+
64+
const value = 10.32134;
65+
const serialized = serializer.serializeFromType(value, 'float');
66+
const deserialized = deserializer.deserializeFromType(serialized, 'float');
67+
68+
expect(value).toBe(deserialized);
69+
})
70+
71+
test('Optional', () => {
72+
const serializer = new Serializer();
73+
const deserializer = new Deserializer();
74+
75+
const valueEmptyInt = null;
76+
const serializedEmptyInt = serializer.serializeFromType(valueEmptyInt, 'int?');
77+
const deserializedEmptyInt = deserializer.deserializeFromType(serializedEmptyInt, 'int?');
78+
79+
expect(deserializedEmptyInt).toBe(valueEmptyInt);
80+
81+
const valueInt = 300;
82+
const serializedInt = serializer.serializeFromType(valueInt, 'int?');
83+
const deserializedInt = deserializer.deserializeFromType(serializedInt, 'int?');
84+
85+
expect(deserializedInt).toBe(valueInt);
86+
87+
const valueEmptyBool = null;
88+
const serializedEmptyBool = serializer.serializeFromType(valueEmptyBool, 'bool?');
89+
const deserializedEmptyBool = deserializer.deserializeFromType(serializedEmptyBool, 'bool?');
90+
91+
expect(deserializedEmptyBool).toBe(valueEmptyBool);
92+
93+
const valueBool = true;
94+
const serializedBool = serializer.serializeFromType(valueBool, 'bool?');
95+
const deserializedBool = deserializer.deserializeFromType(serializedBool, 'bool?');
96+
97+
expect(deserializedBool).toBe(valueBool);
98+
99+
const valueEmptyStr = null;
100+
const serializedEmptyStr = serializer.serializeFromType(valueEmptyStr, 'str?');
101+
const deserializedEmptyStr = deserializer.deserializeFromType(serializedEmptyStr, 'str?');
102+
103+
expect(deserializedEmptyStr).toBe(valueEmptyStr);
104+
105+
const valueStr = 'test';
106+
const serializedStr = serializer.serializeFromType(valueStr, 'str?');
107+
const deserializedStr = deserializer.deserializeFromType(serializedStr, 'str?');
108+
109+
expect(deserializedStr).toBe(valueStr);
110+
111+
const valueEmptyBytes = null;
112+
const serializedEmptyBytes = serializer.serializeFromType(valueEmptyBytes, 'bytes?');
113+
const deserializedEmptyBytes = deserializer.deserializeFromType(serializedEmptyBytes, 'bytes?');
114+
115+
expect(deserializedEmptyBytes).toBe(valueEmptyBytes);
116+
117+
const valueBytes = Buffer.from([0x74, 0x65, 0x73, 0x74]);
118+
const serializedBytes = serializer.serializeFromType(valueBytes, 'bytes?');
119+
const deserializedBytes = deserializer.deserializeFromType(serializedBytes, 'bytes?');
120+
121+
expect(deserializedBytes.equals(valueBytes)).toBe(true);
122+
123+
const valueEmptyFloat = null;
124+
const serializedEmptyFloat = serializer.serializeFromType(valueEmptyFloat, 'float?');
125+
const deserializedEmptyFloat = deserializer.deserializeFromType(serializedEmptyFloat, 'float?');
126+
127+
expect(deserializedEmptyFloat).toBe(valueEmptyFloat);
128+
129+
const valueFloat = 10.32134;
130+
const serializedFloat = serializer.serializeFromType(valueFloat, 'float?');
131+
const deserializedFloat = deserializer.deserializeFromType(serializedFloat, 'float?');
132+
133+
expect(deserializedFloat).toBe(valueFloat);
134+
})
135+
136+
test('Signed', () => {
137+
const serializer = new Serializer();
138+
const deserializer = new Deserializer();
139+
140+
const valueInt = '74657374,300,int';
141+
const serializedInt = serializer.serializeFromType(valueInt, 'SignedData[int]');
142+
const deserializedInt = deserializer.deserializeFromType(serializedInt, 'SignedData[int]');
143+
144+
expect(valueInt).toBe(deserializedInt);
145+
146+
const valueStr = '74657374,test,str';
147+
const serializedStr = serializer.serializeFromType(valueStr, 'SignedData[str]');
148+
const deserializedStr = deserializer.deserializeFromType(serializedStr, 'SignedData[str]');
149+
150+
expect(valueStr).toBe(deserializedStr);
151+
152+
const valueBytes = '74657374,74657374,bytes';
153+
const serializedBytes = serializer.serializeFromType(valueBytes, 'SignedData[bytes]');
154+
const deserializedBytes = deserializer.deserializeFromType(serializedBytes, 'SignedData[bytes]');
155+
156+
expect(valueBytes).toBe(deserializedBytes);
157+
158+
const valueFloat = '74657374,10.32134,float';
159+
const serializedFloat = serializer.serializeFromType(valueFloat, 'SignedData[float]');
160+
const deserializedFloat = deserializer.deserializeFromType(serializedFloat, 'SignedData[float]');
161+
162+
expect(valueFloat).toBe(deserializedFloat);
163+
164+
const valueBoolFalse = '74657374,false,bool';
165+
const serializedBoolFalse = serializer.serializeFromType(valueBoolFalse, 'SignedData[bool]');
166+
const deserializedBoolFalse = deserializer.deserializeFromType(serializedBoolFalse, 'SignedData[bool]');
167+
168+
expect(valueBoolFalse).toBe(deserializedBoolFalse);
169+
170+
const valueBoolTrue = '74657374,true,bool';
171+
const serializedBoolTrue = serializer.serializeFromType(valueBoolTrue, 'SignedData[bool]');
172+
const deserializedBoolTrue = deserializer.deserializeFromType(serializedBoolTrue, 'SignedData[bool]');
173+
174+
expect(valueBoolTrue).toBe(deserializedBoolTrue);
175+
})

__tests__/nano_contracts/serializer.test.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,20 @@ test('List', () => {
5050

5151
test('Optional', () => {
5252
const serializer = new Serializer();
53-
expect(serializer.fromOptional(true, undefined, 'int').equals(Buffer.from([0x00]))).toBe(true);
54-
expect(serializer.fromOptional(false, 300, 'int').equals(Buffer.from([0x01, 0x00, 0x00, 0x01, 0x2c]))).toBe(true);
53+
expect(serializer.fromOptional(null, 'int').equals(Buffer.from([0x00]))).toBe(true);
54+
expect(serializer.fromOptional(300, 'int').equals(Buffer.from([0x01, 0x00, 0x00, 0x01, 0x2c]))).toBe(true);
5555

56-
expect(serializer.fromOptional(true, undefined, 'bool').equals(Buffer.from([0x00]))).toBe(true);
57-
expect(serializer.fromOptional(false, true, 'bool').equals(Buffer.from([0x01, 0x01]))).toBe(true);
56+
expect(serializer.fromOptional(null, 'bool').equals(Buffer.from([0x00]))).toBe(true);
57+
expect(serializer.fromOptional(true, 'bool').equals(Buffer.from([0x01, 0x01]))).toBe(true);
5858

59-
expect(serializer.fromOptional(true, undefined, 'str').equals(Buffer.from([0x00]))).toBe(true);
60-
expect(serializer.fromOptional(false, 'test', 'str').equals(Buffer.from([0x01, 0x74, 0x65, 0x73, 0x74]))).toBe(true);
59+
expect(serializer.fromOptional(null, 'str').equals(Buffer.from([0x00]))).toBe(true);
60+
expect(serializer.fromOptional('test', 'str').equals(Buffer.from([0x01, 0x74, 0x65, 0x73, 0x74]))).toBe(true);
6161

62-
expect(serializer.fromOptional(true, undefined, 'bytes').equals(Buffer.from([0x00]))).toBe(true);
63-
expect(serializer.fromOptional(false, [0x74, 0x65, 0x73, 0x74], 'bytes').equals(Buffer.from([0x01, 0x74, 0x65, 0x73, 0x74]))).toBe(true);
62+
expect(serializer.fromOptional(null, 'bytes').equals(Buffer.from([0x00]))).toBe(true);
63+
expect(serializer.fromOptional([0x74, 0x65, 0x73, 0x74], 'bytes').equals(Buffer.from([0x01, 0x74, 0x65, 0x73, 0x74]))).toBe(true);
6464

65-
expect(serializer.fromOptional(true, undefined, 'float').equals(Buffer.from([0x00]))).toBe(true);
66-
expect(serializer.fromOptional(false, 10.32134, 'float').equals(Buffer.from([0x01, 0x40, 0x24, 0xa4, 0x86, 0xad, 0x2d, 0xcb, 0x14]))).toBe(true);
65+
expect(serializer.fromOptional(null, 'float').equals(Buffer.from([0x00]))).toBe(true);
66+
expect(serializer.fromOptional(10.32134, 'float').equals(Buffer.from([0x01, 0x40, 0x24, 0xa4, 0x86, 0xad, 0x2d, 0xcb, 0x14]))).toBe(true);
6767
})
6868

6969
test('Signed', () => {

0 commit comments

Comments
 (0)