Skip to content

Commit

Permalink
Merge pull request #93 from tonlabs/0.22.1-rc
Browse files Browse the repository at this point in the history
### Fixed- GraphQL query will retry if network error has occurred
  • Loading branch information
AlexeyVavilin authored Apr 29, 2020
2 parents 6483a69 + ec1356c commit cdeb088
Show file tree
Hide file tree
Showing 8 changed files with 434 additions and 225 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Release Notes
All notable changes to this project will be documented in this file.

## 0.22.1 - Apr 29, 2020
### Fixed
- GraphQL query will retry if network error has occurred

### New
- `aggregate` method of `TONQueriesModuleCollection`

## 0.22.0 - Apr 20, 2020
### Featured
- Aggregation queries
Expand Down
72 changes: 63 additions & 9 deletions __tests__/contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

// @flow

import { Span } from 'opentracing';
import { removeProps, TONAddressStringVariant } from '../src/modules/TONContractsModule';
import { TONOutputEncoding } from '../src/modules/TONCryptoModule';
import { TONClient, TONClientError } from '../src/TONClient';
import {Span} from 'opentracing';
import {removeProps, TONAddressStringVariant} from '../src/modules/TONContractsModule';
import {TONOutputEncoding} from '../src/modules/TONCryptoModule';
import {TONClient, TONClientError} from '../src/TONClient';


import type { TONContractLoadResult } from '../types';
import { binariesVersion } from './_/binaries';
import { ABIVersions, tests } from './_/init-tests';
import type {TONContractABI, TONContractLoadResult, TONKeyPairData} from '../types';
import {binariesVersion} from './_/binaries';
import {ABIVersions, tests} from './_/init-tests';


const WalletContractPackage = tests.loadPackage('WalletContract');
Expand Down Expand Up @@ -248,7 +248,7 @@ test('External Signing on ABI v1', async () => {
};
const unsignedMessage = await contracts.createUnsignedDeployMessage(deployParams);
const signKey = await crypto.naclSignKeypairFromSecretKey(keys.secret);
const signBytesBase64 = await crypto.naclSignDetached({
let signBytesBase64 = await crypto.naclSignDetached({
base64: unsignedMessage.signParams.bytesToSignBase64,
}, signKey.secret, TONOutputEncoding.Base64);
const signed = await contracts.createSignedDeployMessage({
Expand All @@ -260,6 +260,33 @@ test('External Signing on ABI v1', async () => {
const message = await contracts.createDeployMessage(deployParams);
expect(signed.message.messageBodyBase64)
.toEqual(message.message.messageBodyBase64);

const unsignedRunMessage = await contracts.createUnsignedRunMessage({
address: message.address,
abi: eventsPackage.abi,
functionName: 'returnValue',
input: { id: '0' },
keyPair: keys,
});
signBytesBase64 = await crypto.naclSignDetached({
base64: unsignedRunMessage.signParams.bytesToSignBase64,
}, signKey.secret, TONOutputEncoding.Base64);

const signedRunMessage = await contracts.createSignedRunMessage({
unsignedMessage: unsignedRunMessage,
signBytesBase64,
publicKeyHex: keys.public,
});
const runMessage = await contracts.createRunMessage({
address: message.address,
abi: eventsPackage.abi,
functionName: 'returnValue',
input: { id: '0' },
keyPair: keys,
});

expect(signedRunMessage.message.messageBodyBase64)
.toEqual(runMessage.message.messageBodyBase64);
});

test('External Signing on ABI v2', async () => {
Expand All @@ -278,9 +305,10 @@ test('External Signing on ABI v2', async () => {
};
const unsignedMessage = await contracts.createUnsignedDeployMessage(deployParams);
const signKey = await crypto.naclSignKeypairFromSecretKey(keys.secret);
const signBytesBase64 = await crypto.naclSignDetached({
let signBytesBase64 = await crypto.naclSignDetached({
base64: unsignedMessage.signParams.bytesToSignBase64,
}, signKey.secret, TONOutputEncoding.Base64);

const signed = await contracts.createSignedDeployMessage({
signBytesBase64,
unsignedMessage,
Expand All @@ -289,6 +317,32 @@ test('External Signing on ABI v2', async () => {
const message = await contracts.createDeployMessage(deployParams);
expect(signed.message.messageBodyBase64)
.toEqual(message.message.messageBodyBase64);


const messageParams = {
address: message.address,
abi: eventsPackage.abi,
functionName: 'returnValue',
header: {
pubkey: keys.public,
time: Date.now(),
},
input: { id: '0' },
keyPair: keys,
};

const unsignedRunMessage = await contracts.createUnsignedRunMessage(messageParams);
signBytesBase64 = await crypto.naclSignDetached({
base64: unsignedRunMessage.signParams.bytesToSignBase64,
}, signKey.secret, TONOutputEncoding.Base64);
const signedRunMessage = await contracts.createSignedRunMessage({
unsignedMessage: unsignedRunMessage,
signBytesBase64,
});
const runMessage = await contracts.createRunMessage(messageParams);

expect(signedRunMessage.message.messageBodyBase64)
.toEqual(runMessage.message.messageBodyBase64);
});

// TODO return test when data[] will fix in compilers
Expand Down
44 changes: 27 additions & 17 deletions __tests__/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
* limitations under the License.
*/

import TONCryptoModule, { TONMnemonicDictionary, TONOutputEncoding } from "../src/modules/TONCryptoModule";
import { tests } from "./_/init-tests";
import TONCryptoModule, {TONMnemonicDictionary, TONOutputEncoding} from "../src/modules/TONCryptoModule";
import {tests} from "./_/init-tests";

beforeAll(tests.init);
afterAll(tests.done);

const TONMnemonicWordCounts = [12, 15, 18, 21, 24];
test('crypto', async () => {
const crypto: TONCryptoModule = tests.client.crypto;

Expand All @@ -37,7 +37,7 @@ test('crypto', async () => {
const result3 = await crypto.randomGenerateBytes(32, TONOutputEncoding.Hex);
expect(result3.length).toEqual(64);

const resultHexUppercase= await crypto.randomGenerateBytes(32, TONOutputEncoding.HexUppercase);
const resultHexUppercase = await crypto.randomGenerateBytes(32, TONOutputEncoding.HexUppercase);
expect(resultHexUppercase.length).toEqual(64);

const result4 = await crypto.randomGenerateBytes(32, TONOutputEncoding.Base64);
Expand Down Expand Up @@ -80,6 +80,7 @@ test('crypto', async () => {
const result7 = await crypto.naclBoxKeypair();
expect(result7.public.length).toEqual(64);
expect(result7.secret.length).toEqual(64);
expect(result7.public).not.toEqual(result7.secret);

const result8 = await crypto.naclBoxKeypairFromSecretKey('e207b5966fb2c5be1b71ed94ea813202706ab84253bdf4dc55232f82a1caf0d4');
expect(result8.public).toEqual('a53b003d3ffc1e159355cb37332d67fc235a7feb6381e36c803274074dc3933a');
Expand Down Expand Up @@ -165,25 +166,34 @@ test('crypto', async () => {
const mnemonicWords = await crypto.mnemonicWords();
expect(mnemonicWords.split(' ').length).toEqual(2048);

expect((await crypto.mnemonicFromRandom({
dictionary: TONMnemonicDictionary.ENGLISH,
wordCount: 12,
})).split(' ').length).toEqual(12);

for (const dictionary in TONMnemonicDictionary) {
for (let i = 0; i < TONMnemonicWordCounts.length; i++) {
expect((await crypto.mnemonicFromRandom({
dictionary: TONMnemonicDictionary[dictionary],
wordCount: TONMnemonicWordCounts[i],
})).split(' ').length).toEqual(TONMnemonicWordCounts[i]);
}
}
expect(await crypto.mnemonicFromEntropy({
entropy: { hex: '00112233445566778899AABBCCDDEEFF' },
dictionary: TONMnemonicDictionary.ENGLISH,
wordCount: 12,
})).toEqual('abandon math mimic master filter design carbon crystal rookie group knife young');

expect(await crypto.mnemonicIsValid({
dictionary: TONMnemonicDictionary.ENGLISH,
wordCount: 12,
phrase: await crypto.mnemonicFromRandom({
dictionary: TONMnemonicDictionary.ENGLISH,
wordCount: 12,
}),
})).toBeTruthy();
for (const dictionary in TONMnemonicDictionary) {
for (let i = 0; i < TONMnemonicWordCounts.length; i++) {
expect(await crypto.mnemonicIsValid({
dictionary: TONMnemonicDictionary[dictionary],
wordCount: TONMnemonicWordCounts[i],
phrase: await crypto.mnemonicFromRandom({
dictionary: TONMnemonicDictionary[dictionary],
wordCount: TONMnemonicWordCounts[i],
}),
})).toBeTruthy();
}

}

expect(await crypto.mnemonicIsValid({ phrase: 'one two' })).toBeFalsy();

const keys = await crypto.mnemonicDeriveSignKeys({
Expand Down
17 changes: 14 additions & 3 deletions __tests__/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ const WalletContractPackage = tests.loadPackage('WalletContract');
beforeAll(tests.init);
afterAll(tests.done);

test.skip('(not test) Debug network errors during wait for', async () => {
const queries = tests.client.queries;
const accounts = await queries.accounts.waitFor({
filter: { id: { eq: '3333' } },
result: 'id',
timeout: 10000,
});
console.log('>>>', accounts);
});

test('Specialized', async () => {
const queries = tests.client.queries;
let count = await queries.getAccountsCount();
Expand Down Expand Up @@ -64,7 +74,8 @@ test('Block signatures', async () => {
result: 'id',
limit: 1,
});
expect(signatures.length).toBeGreaterThanOrEqual(0);
expect(signatures.length)
.toBeGreaterThanOrEqual(0);
});

test('All Accounts', async () => {
Expand Down Expand Up @@ -117,7 +128,7 @@ const transactionWithAddresses = `
in_message { dst src value }
`;

test.each(ABIVersions)('Subscribe for transactions with addresses (ABI v%i)', async (abiVersion) => {
test.each(ABIVersions)('Subscribe for transactions with addresses (ABIv%i)', async (abiVersion) => {
const { contracts, queries, crypto } = tests.client;
const walletPackage = WalletContractPackage[abiVersion];
const walletKeys = await crypto.ed25519Keypair();
Expand Down Expand Up @@ -210,7 +221,7 @@ test('Aggregations', async () => {
fields: [{ field: 'id', fn: "COUNT" }],
}))[0];
expect(Number(tr)).toBeGreaterThanOrEqual(n);
}
};
const queries = tests.client.queries;
await testCollection(queries.accounts, 1);
await testCollection(queries.blocks, 1);
Expand Down
66 changes: 36 additions & 30 deletions __tests__/test-error-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,24 @@

// @flow

import { ABIVersions, tests } from './_/init-tests';
import { TONMnemonicDictionary } from '../src/modules/TONCryptoModule';
import {ABIVersions, tests} from './_/init-tests';
import {TONMnemonicDictionary} from '../src/modules/TONCryptoModule';

const WalletContractPackage = tests.loadPackage('WalletContract');

beforeAll(tests.init);
afterAll(tests.done);

async function expectError(code: number, source: string, message?: string, f) {
try {
await f();
fail(`Expected error with code:${code} source: ${source}`);
} catch (error) {
expect({ code: error.code, source: error.source }).toEqual({ code, source });
expect(error.message).toMatch(message);
}
}

test.each(ABIVersions)('Test SDK Errors 1-3 (ABI v%i)', async (abiVersion) => {
const { contracts, crypto } = tests.client;
const walletPackage = WalletContractPackage[abiVersion];
Expand Down Expand Up @@ -74,46 +84,26 @@ test.each(ABIVersions)('Test SDK Errors 1-3 (ABI v%i)', async (abiVersion) => {
.toMatch('Invalid params: missing field \`abi\`');
} */

try {
await expectError(2, 'client', 'Invalid params: invalid type: null, expected struct KeyPair', async () => {
await contracts.createDeployMessage({
package: walletPackage,
constructorParams: {},
//$FlowFixMe
keyPair: null,
});
} catch (error) {
expect(error.source)
.toEqual('client');
expect(error.code)
.toEqual(2);
expect(error.data)
.toBeNull();
expect(error.message)
.toMatch('Invalid params: invalid type: null, expected struct KeyPair');
}
});

try {
await expectError(2, 'client', 'Invalid params: missing field `public`', async () => {
await contracts.createDeployMessage({
package: walletPackage,
constructorParams: {},
//$FlowFixMe
keyPair: {},
});
} catch (error) {
expect(error.source)
.toEqual('client');
expect(error.code)
.toEqual(2);
expect(error.data)
.toBeNull();
expect(error.message)
.toMatch('Invalid params: missing field `public`');
}
});

try {
await contracts.createDeployMessage({
package: walletPackage,
constructorParams: {},
//$FlowFixMe
keyPair: '',
});
} catch (error) {
Expand Down Expand Up @@ -148,8 +138,8 @@ test.each(ABIVersions)('Test SDK Errors > 2000 (ABI v%i)', async (abiVersion) =>
.toEqual(2001);
expect(error.data)
.toBeNull();
/* expect(error.message)
.toMatch('Invalid public key [PublicKey must be 32 bytes in length]');*/
expect(error.message)
.toMatch('Invalid public key [PublicKey must be 32 bytes in length]');
}


Expand Down Expand Up @@ -218,6 +208,22 @@ test.each(ABIVersions)('Test SDK Errors > 2000 (ABI v%i)', async (abiVersion) =>
expect(error.message)
.toMatch('Invalid factorize challenge: invalid digit found in string');
}
try {
await crypto.mnemonicFromEntropy({
entropy: { hex: '' },
dictionary: TONMnemonicDictionary.ENGLISH,
});
} catch (error) {
expect(error.source)
.toEqual('client');
expect(error.code)
.toEqual(2016);
expect(error.data)
.toBeNull();
expect(error.message)
.toMatch('Invalid bip39 entropy:');
}

try {
await crypto.hdkeyXPrvDerivePath('???', '', true);
} catch (error) {
Expand Down Expand Up @@ -247,7 +253,7 @@ test.each(ABIVersions)('Test SDK Errors > 2000 (ABI v%i)', async (abiVersion) =>
try {
await crypto.mnemonicFromRandom({
dictionary: TONMnemonicDictionary[dict],
//$FlowFixMe
//$FlowFixMe
wordCount: 1,
});
} catch (error) {
Expand Down
Loading

0 comments on commit cdeb088

Please sign in to comment.