Skip to content

Commit a06829f

Browse files
authored
feat: Thor solo account seeding (#217)
* feat: thor leveldb dump for account seeding * feat: docker file for database init from local to container * refactor: docker-compose for dockerfile build and additional needed commands * feat: test accounts fixture * refactor: group renaming * test: vet & vtho account balances * refactor: removed thor db logs * test: increased timeout * chore: spacing * docs: minor tsdocs changes * docs: minor tsdocs changes * docs: contributing update for test accounts guideline
1 parent 1d06367 commit a06829f

File tree

15 files changed

+273
-5
lines changed

15 files changed

+273
-5
lines changed

CONTRIBUTING.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ To ensure consistency throughout the source code, please adhere to the following
1616
1. Follow the coding style used throughout the project. The project includes an ESLint configuration, so consider installing an ESLint plugin for your text editor for real-time linting.
1717
2. All public API methods must be documented.
1818
3. Write tests for new features and bug fixes.
19-
4. We follow [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) for commit messages.
19+
4. For integration tests using thor-solo, if needed, use a `TEST_ACCOUNT` in order to isolate previous integration tests.
20+
5. We follow [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) for commit messages.
2021

2122
# Commenting Guidelines
2223

Dockerfile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This Dockerfile is used to build a Thor solo node image based on vechain/thor:v2.1.0
2+
# The initial database directory is copied to the container
3+
# Thor solo then sets up the database with the specified --data-dir in the docker-compose.yml file
4+
FROM vechain/thor:v2.1.0
5+
6+
# Delete /data/thor directory
7+
RUN rm -rf /data/thor
8+
9+
# Copy the initial database directory to the container
10+
COPY ./thor-solo /data/thor

docker-compose.yaml

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ version: "3.9"
22

33
services:
44
thor-solo:
5-
image: vechain/thor:v2.1.0
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
68
container_name: thor-solo
9+
user: root
710
ports:
811
- 8669:8669
912
command:
@@ -16,6 +19,10 @@ services:
1619
- --txpool-limit=100000000000 # limit txpool size
1720
- --txpool-limit-per-account=256 # limit txpool size per account
1821
- --cache=1024 # megabytes of ram allocated to trie nodes cache
22+
- --data-dir=/data/thor # data directory
23+
- --verbosity=9
24+
- --persist
25+
1926
healthcheck:
2027
# We run the health check using standard UNIX tools so we don't have to
2128
# install additional dependencies in the container.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { describe, expect, test } from '@jest/globals';
2+
import { TEST_ACCOUNTS, thorSoloClient } from '../../../fixture';
3+
4+
/**
5+
* Prolong timeout due to block time which sometimes exceeds jest's default timeout of 5 seconds.
6+
*/
7+
const TIMEOUT = 20000;
8+
9+
/**
10+
* ThorClient - AccountClient class tests
11+
*
12+
* @group integration/client/thor/accounts
13+
*/
14+
describe('ThorClient - Accounts', () => {
15+
/**
16+
* getAccount tests
17+
*/
18+
describe('getAccount', () => {
19+
/**
20+
* Tests VET balance and VTHO balance of test account
21+
* Checks also if VTHO is generated after a block is produced due to positive VET balance
22+
*/
23+
test(
24+
'Get account returns fixed VET balance and increased VTHO balance with block number increase',
25+
async () => {
26+
const accountBefore = await thorSoloClient.accounts.getAccount(
27+
TEST_ACCOUNTS.account.address
28+
);
29+
30+
expect(accountBefore).toBeDefined();
31+
expect(accountBefore.balance).toEqual(
32+
'0x19d971e4fe8401e74000000'
33+
);
34+
expect(Number(accountBefore.energy)).toBeGreaterThan(
35+
500000000 * 10 ** 18
36+
);
37+
38+
const currentBlock =
39+
await thorSoloClient.blocks.getBlock('best');
40+
41+
let latestBlock;
42+
43+
// Wait for a block greater than currentBlock
44+
do {
45+
latestBlock = await thorSoloClient.blocks.getBlock('best');
46+
await new Promise((resolve) => setTimeout(resolve, 1000));
47+
} while (currentBlock.number === latestBlock.number);
48+
49+
const accountAfter = await thorSoloClient.accounts.getAccount(
50+
TEST_ACCOUNTS.account.address
51+
);
52+
53+
expect(accountAfter).toBeDefined();
54+
expect(accountAfter.balance).toEqual(accountBefore.balance);
55+
expect(Number(accountAfter.energy)).toBeGreaterThan(
56+
Number(accountBefore.energy)
57+
);
58+
},
59+
TIMEOUT
60+
);
61+
});
62+
});

packages/network/tests/client/thor-client/blocks/blocks.testnet.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { validBlockRevisions, invalidBlockRevisions } from './fixture';
33
import { thorClient } from '../../../fixture';
44

55
/**
6-
* ThorClient class tests
6+
* ThorClient - BlockClient class tests
77
*
88
* @group integration/client/thor/blocks
99
*/

packages/network/tests/fixture.ts

+144-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,150 @@ const testAccount = '0xf077b491b355E64048cE21E3A6Fc4751eEeA77fa';
3131
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
3232

3333
/**
34-
* Thor client instance fixture
34+
* Thor client testnet instance fixture
3535
*/
3636
const thorClient = new ThorClient(testNetwork);
3737

38-
export { testNetwork, soloNetwork, ZERO_ADDRESS, testAccount, thorClient };
38+
/**
39+
* Thor client solo instance fixture
40+
*/
41+
const thorSoloClient = new ThorClient(soloNetwork);
42+
43+
/**
44+
* All available accounts for testing purposes
45+
*/
46+
const ALL_ACCOUNTS = [
47+
/* ----------- NEW ACCOUNTS ----------- */
48+
/**
49+
* Each new account starts with
50+
* - VET: 500000000
51+
* - VTHO: at least 500000000 (VTHO is not constant due to generation when having VET)
52+
*/
53+
{
54+
privateKey:
55+
'7f9290cc44c5fd2b95fe21d6ad6fe5fa9c177e1cd6f3b4c96a97b13e09eaa158',
56+
address: '0x3db469a79593dcc67f07de1869d6682fc1eaf535'
57+
},
58+
{
59+
privateKey:
60+
'ea5383ac1f9e625220039a4afac6a7f868bf1ad4f48ce3a1dd78bd214ee4ace5',
61+
address: '0x2669514f9fe96bc7301177ba774d3da8a06cace4'
62+
},
63+
{
64+
privateKey:
65+
'1758771c54938e977518e4ff1c297aca882f6598891df503030734532efa790e',
66+
address: '0x9e7911de289c3c856ce7f421034f66b6cde49c39'
67+
},
68+
{
69+
privateKey:
70+
'432f38bcf338c374523e83fdb2ebe1030aba63c7f1e81f7d76c5f53f4d42e766',
71+
address: '0x88b2551c3ed42ca663796c10ce68c88a65f73fe2'
72+
},
73+
{
74+
privateKey:
75+
'706e6acd567fdc22db54aead12cb39db01c4832f149f95299aa8dd8bef7d28ff',
76+
address: '0xf02f557c753edf5fcdcbfe4c1c3a448b3cc84d54'
77+
},
78+
{
79+
privateKey:
80+
'f9fc826b63a35413541d92d2bfb6661128cd5075fcdca583446d20c59994ba26',
81+
address: '0x7a28e7361fd10f4f058f9fefc77544349ecff5d6'
82+
},
83+
{
84+
privateKey:
85+
'0da72e8e26580d409d1837e23cc50c887358964152039e32af0c8a147c6b616d',
86+
address: '0xb717b660cd51109334bd10b2c168986055f58c1a'
87+
},
88+
{
89+
privateKey:
90+
'6e8ad4e4ffb888082d94975a58dc9a8179f8724ba22301cd8392ba5352af7e25',
91+
address: '0x62226ae029dabcf90f3cb66f091919d2687d5257'
92+
},
93+
{
94+
privateKey:
95+
'521b7793c6eb27d137b617627c6b85d57c0aa303380e9ca4e30a30302fbc6676',
96+
address: '0x062f167a905c1484de7e75b88edc7439f82117de'
97+
},
98+
{
99+
privateKey:
100+
'adc81265b0909dec70235ec973b1758e45ce5ce7cfe92eb96b79cd0ef07bc6bc',
101+
address: '0x3e3d79163b08502a086213cd09660721740443d7'
102+
},
103+
/* ----------- THOR SOLO GENESIS ACCOUNTS ----------- */
104+
/**
105+
* Each Thor Solo genesis account has
106+
* - VET: 500000000
107+
* - VTHO: at least 1365000000 (VTHO is not constant due to generation when having VET)
108+
*/
109+
{
110+
privateKey:
111+
'99f0500549792796c14fed62011a51081dc5b5e68fe8bd8a13b86be829c4fd36',
112+
address: '0xf077b491b355e64048ce21e3a6fc4751eeea77fa'
113+
},
114+
{
115+
privateKey:
116+
'7b067f53d350f1cf20ec13df416b7b73e88a1dc7331bc904b92108b1e76a08b1',
117+
address: '0x435933c8064b4ae76be665428e0307ef2ccfbd68'
118+
},
119+
{
120+
privateKey:
121+
'f4a1a17039216f535d42ec23732c79943ffb45a089fbb78a14daad0dae93e991',
122+
address: '0x0f872421dc479f3c11edd89512731814d0598db5'
123+
},
124+
{
125+
privateKey:
126+
'35b5cc144faca7d7f220fca7ad3420090861d5231d80eb23e1013426847371c4',
127+
address: '0xf370940abdbd2583bc80bfc19d19bc216c88ccf0'
128+
},
129+
{
130+
privateKey:
131+
'10c851d8d6c6ed9e6f625742063f292f4cf57c2dbeea8099fa3aca53ef90aef1',
132+
address: '0x99602e4bbc0503b8ff4432bb1857f916c3653b85'
133+
},
134+
{
135+
privateKey:
136+
'2dd2c5b5d65913214783a6bd5679d8c6ef29ca9f2e2eae98b4add061d0b85ea0',
137+
address: '0x61e7d0c2b25706be3485980f39a3a994a8207acf'
138+
},
139+
{
140+
privateKey:
141+
'e1b72a1761ae189c10ec3783dd124b902ffd8c6b93cd9ff443d5490ce70047ff',
142+
address: '0x361277d1b27504f36a3b33d3a52d1f8270331b8c'
143+
},
144+
{
145+
privateKey:
146+
'35cbc5ac0c3a2de0eb4f230ced958fd6a6c19ed36b5d2b1803a9f11978f96072',
147+
address: '0xd7f75a0a1287ab2916848909c8531a0ea9412800'
148+
},
149+
{
150+
privateKey:
151+
'b639c258292096306d2f60bc1a8da9bc434ad37f15cd44ee9a2526685f592220',
152+
address: '0xabef6032b9176c186f6bf984f548bda53349f70a'
153+
},
154+
{
155+
privateKey:
156+
'9d68178cdc934178cca0a0051f40ed46be153cf23cb1805b59cc612c0ad2bbe0',
157+
address: '0x865306084235bf804c8bba8a8d56890940ca8f0b'
158+
}
159+
];
160+
161+
/**
162+
* Test accounts fixture
163+
*/
164+
const TEST_ACCOUNTS = {
165+
/**
166+
* Accounts dedicated for testing account related operations.
167+
*/
168+
account: ALL_ACCOUNTS[0]
169+
};
170+
171+
export {
172+
testNetwork,
173+
soloNetwork,
174+
ZERO_ADDRESS,
175+
testAccount,
176+
thorClient,
177+
thorSoloClient,
178+
TEST_ACCOUNTS,
179+
ALL_ACCOUNTS
180+
};
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
MANIFEST-000010
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
MANIFEST-000007

thor-solo/instance-a4988aba7aea69f6-v3/main.db/LOCK

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
=============== Nov 9, 2023 (UTC) ===============
2+
12:14:41.949498 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed
3+
12:14:41.951641 db@open opening
4+
12:14:41.954698 version@stat F·[] S·0B[] Sc·[]
5+
12:14:41.955351 db@janitor F·2 G·0
6+
12:14:41.955359 db@open done T·3.708208ms
7+
12:15:06.734576 db@close closing
8+
12:15:06.734769 db@close done T·194.333µs
9+
=============== Nov 9, 2023 (UTC) ===============
10+
12:15:09.891096 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed
11+
12:15:09.891540 version@stat F·[] S·0B[] Sc·[]
12+
12:15:09.891561 db@open opening
13+
12:15:09.891589 journal@recovery F·1
14+
12:15:09.895037 journal@recovery recovering @1
15+
12:15:09.896911 memdb@flush created L0@2 N·159 S·17KiB "\x00\x00\x00..\x00\x00\x00,v46":"\x03st..?dC,v52"
16+
12:15:09.899539 version@stat F·[1] S·17KiB[17KiB] Sc·[0.25]
17+
12:15:09.902261 db@janitor F·3 G·0
18+
12:15:09.902277 db@open done T·10.712166ms
19+
12:15:19.822433 db@close closing
20+
12:15:19.822547 db@close done T·114µs
21+
=============== Nov 9, 2023 (UTC) ===============
22+
12:19:58.372493 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed
23+
12:19:58.379413 version@stat F·[1] S·17KiB[17KiB] Sc·[0.25]
24+
12:19:58.379791 db@open opening
25+
12:19:58.380221 journal@recovery F·1
26+
12:19:58.384509 journal@recovery recovering @3
27+
12:19:58.388672 memdb@flush created L0@5 N·52 S·9KiB "\x00\x00\x00..\x00\x00\x00,v205":"\x03st..?dC,v209"
28+
12:19:58.393181 version@stat F·[2] S·26KiB[26KiB] Sc·[0.50]
29+
12:19:58.400374 db@janitor F·4 G·0
30+
12:19:58.400601 db@open done T·20.483834ms
31+
12:20:57.225641 db@close closing
32+
12:20:57.226214 db@close done T·572.208µs
33+
=============== Nov 9, 2023 (UTC) ===============
34+
12:21:00.233303 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed
35+
12:21:00.237557 version@stat F·[2] S·26KiB[26KiB] Sc·[0.50]
36+
12:21:00.238620 db@open opening
37+
12:21:00.239352 journal@recovery F·1
38+
12:21:00.242615 journal@recovery recovering @6
39+
12:21:00.246760 memdb@flush created L0@8 N·100 S·12KiB "\x00\x00\x00..\x00\x00\x00,v258":"\x03st..?dC,v264"
40+
12:21:00.250789 version@stat F·[3] S·39KiB[39KiB] Sc·[0.75]
41+
12:21:00.256763 db@janitor F·5 G·0
42+
12:21:00.259896 db@open done T·20.662292ms
43+
12:21:06.386084 db@close closing
44+
12:21:06.388216 db@close done T·2.129208ms
Binary file not shown.

0 commit comments

Comments
 (0)