Skip to content

Commit 9eaceff

Browse files
Merge pull request #668 from HathorNetwork/release-candidate
Release v1.6.0
2 parents b18bc0d + 721cef9 commit 9eaceff

File tree

13 files changed

+1330
-1105
lines changed

13 files changed

+1330
-1105
lines changed

__tests__/storage/leveldb/leveldb_store.test.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,17 +405,20 @@ test('nano contract methods', async () => {
405405
await store.registerNanoContract('001', {
406406
ncId: '001',
407407
blueprintId: '001',
408-
blueprintName: 'Bet'
408+
blueprintName: 'Bet',
409+
address: 'abc',
409410
});
410411
await expect(store.getNanoContract('001')).resolves.toBeDefined();
412+
await expect(store.getNanoContract('001')).resolves.toMatchObject({ address: 'abc' });
411413
await expect(store.isNanoContractRegistered('001')).resolves.toBeTruthy();
412414
await expect(asyncGenToArray(store.nanoContractIndex.registeredDB.iterator()))
413415
.resolves.toHaveLength(1);
414416

415417
await store.registerNanoContract('002', {
416418
ncId: '002',
417419
blueprintId: '001',
418-
blueprintName: 'Bet'
420+
blueprintName: 'Bet',
421+
address: 'abc',
419422
});
420423
await expect(store.getNanoContract('002')).resolves.toBeDefined();
421424
await expect(store.isNanoContractRegistered('002')).resolves.toBeTruthy();
@@ -429,6 +432,10 @@ test('nano contract methods', async () => {
429432
await expect(asyncGenToArray(store.nanoContractIndex.registeredDB.iterator()))
430433
.resolves.toHaveLength(1);
431434

435+
// Test update address of registered nano contract
436+
await store.updateNanoContractRegisteredAddress('001', 'def');
437+
await expect(store.getNanoContract('001')).resolves.toMatchObject({ address: 'def' });
438+
432439
// Asserts store is cleaned only when tokens are cleaned too
433440
await store.cleanStorage(false, false, false); // not cleaning tokens
434441
await expect(asyncGenToArray(store.nanoContractIndex.registeredDB.iterator()))

__tests__/storage/memory_store.test.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,16 +345,19 @@ test('nano contract methods', async () => {
345345
await store.registerNanoContract('001', {
346346
ncId: '001',
347347
blueprintId: '001',
348-
blueprintName: 'Bet'
348+
blueprintName: 'Bet',
349+
address: 'abc',
349350
});
350351
await expect(store.getNanoContract('001')).resolves.toBeDefined();
352+
await expect(store.getNanoContract('001')).resolves.toMatchObject({ address: 'abc' });
351353
await expect(store.isNanoContractRegistered('001')).resolves.toBeTruthy();
352354
expect(store.registeredNanoContracts.size).toEqual(1);
353355

354356
await store.registerNanoContract('002', {
355357
ncId: '002',
356358
blueprintId: '001',
357-
blueprintName: 'Bet'
359+
blueprintName: 'Bet',
360+
address: 'abc',
358361
});
359362
await expect(store.getNanoContract('002')).resolves.toBeDefined();
360363
await expect(store.isNanoContractRegistered('002')).resolves.toBeTruthy();
@@ -366,6 +369,10 @@ test('nano contract methods', async () => {
366369
await expect(store.isNanoContractRegistered('002')).resolves.toBeFalsy();
367370
expect(store.registeredNanoContracts.size).toEqual(1);
368371

372+
// Test update address of registered nano contract
373+
await store.updateNanoContractRegisteredAddress('001', 'def');
374+
await expect(store.getNanoContract('001')).resolves.toMatchObject({ address: 'def' });
375+
369376
// Asserts store is cleaned only when tokens are cleaned too
370377
await store.cleanStorage(false, false, false); // not cleaning tokens
371378
expect(store.registeredNanoContracts.size).toEqual(1);

__tests__/storage/storage.test.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ describe('handleStop', () => {
6464
outputs: [],
6565
});
6666
await storage.registerToken(testToken);
67+
const address0 = await storage.getAddressAtIndex(0);
68+
const address1 = await storage.getAddressAtIndex(1);
69+
const testNano = {
70+
ncId: 'abc',
71+
address: address0.base58,
72+
blueprintId: 'blueprintId',
73+
blueprintName: 'blueprintName',
74+
};
75+
await storage.registerNanoContract('abc', testNano);
6776
// We have 1 transaction
6877
await expect(store.historyCount()).resolves.toEqual(1);
6978
// 20 addresses
@@ -72,6 +81,20 @@ describe('handleStop', () => {
7281
let tokens = await toArray(storage.getRegisteredTokens());
7382
expect(tokens).toHaveLength(1);
7483
expect(tokens[0]).toEqual(testToken);
84+
// And 1 registered nano contract
85+
let nanos = await toArray(storage.getRegisteredNanoContracts());
86+
expect(nanos).toHaveLength(1);
87+
expect(nanos[0]).toEqual(testNano);
88+
89+
// Test address update
90+
await expect(store.getNanoContract('abc')).resolves.toMatchObject({ address: address0.base58 });
91+
await storage.updateNanoContractRegisteredAddress('abc', address1.base58);
92+
await expect(store.getNanoContract('abc')).resolves.toMatchObject({ address: address1.base58 });
93+
94+
await expect(storage.updateNanoContractRegisteredAddress('abc', 'abc')).rejects.toThrow(Error);
95+
96+
// Go back to default address
97+
await storage.updateNanoContractRegisteredAddress('abc', address0.base58);
7598

7699
storage.version = 'something';
77100
// handleStop with defaults
@@ -82,19 +105,27 @@ describe('handleStop', () => {
82105
await expect(store.historyCount()).resolves.toEqual(1);
83106
await expect(store.addressCount()).resolves.toEqual(20);
84107
await expect(store.isTokenRegistered(testToken.uid)).resolves.toBeTruthy();
108+
await expect(store.isNanoContractRegistered(testNano.ncId)).resolves.toBeTruthy();
85109
tokens = await toArray(storage.getRegisteredTokens());
86110
expect(tokens).toHaveLength(1);
87111
expect(tokens[0]).toEqual(testToken);
112+
nanos = await toArray(storage.getRegisteredNanoContracts());
113+
expect(nanos).toHaveLength(1);
114+
expect(nanos[0]).toEqual(testNano);
88115

89116
// handleStop with cleanStorage = true
90117
await storage.handleStop({ cleanStorage: true });
91118
// Will clean the history bit not addresses or registered tokens
92119
await expect(store.historyCount()).resolves.toEqual(0);
93120
await expect(store.addressCount()).resolves.toEqual(20);
94121
await expect(store.isTokenRegistered(testToken.uid)).resolves.toBeTruthy();
122+
await expect(store.isNanoContractRegistered(testNano.ncId)).resolves.toBeTruthy();
95123
tokens = await toArray(storage.getRegisteredTokens());
96124
expect(tokens).toHaveLength(1);
97125
expect(tokens[0]).toEqual(testToken);
126+
nanos = await toArray(storage.getRegisteredNanoContracts());
127+
expect(nanos).toHaveLength(1);
128+
expect(nanos[0]).toEqual(testNano);
98129

99130
await storage.addTx({
100131
tx_id: 'another-new-tx',
@@ -109,9 +140,13 @@ describe('handleStop', () => {
109140
await expect(store.historyCount()).resolves.toEqual(1);
110141
await expect(store.addressCount()).resolves.toEqual(0);
111142
await expect(store.isTokenRegistered(testToken.uid)).resolves.toBeTruthy();
143+
await expect(store.isNanoContractRegistered(testNano.ncId)).resolves.toBeTruthy();
112144
tokens = await toArray(storage.getRegisteredTokens());
113145
expect(tokens).toHaveLength(1);
114146
expect(tokens[0]).toEqual(testToken);
147+
nanos = await toArray(storage.getRegisteredNanoContracts());
148+
expect(nanos).toHaveLength(1);
149+
expect(nanos[0]).toEqual(testNano);
115150

116151
// handleStop with cleanAddresses = true
117152
await loadAddresses(0, 20, storage);
@@ -120,6 +155,12 @@ describe('handleStop', () => {
120155
await expect(store.historyCount()).resolves.toEqual(1);
121156
await expect(store.addressCount()).resolves.toEqual(20);
122157
await expect(store.isTokenRegistered(testToken.uid)).resolves.toBeFalsy();
158+
await expect(store.isNanoContractRegistered(testNano.ncId)).resolves.toBeFalsy();
159+
160+
tokens = await toArray(storage.getRegisteredTokens());
161+
expect(tokens).toHaveLength(0);
162+
nanos = await toArray(storage.getRegisteredNanoContracts());
163+
expect(nanos).toHaveLength(0);
123164

124165
// Access data is untouched when stopping the wallet
125166
// XXX: since we stringify to save on store, the optional undefined properties are removed

babel.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ module.exports = {
1414
],
1515
plugins: [
1616
"@babel/plugin-transform-async-generator-functions",
17-
"@babel/plugin-proposal-class-properties",
17+
"@babel/plugin-transform-class-properties",
1818
],
1919
};

0 commit comments

Comments
 (0)