2019-05-15 01:25:46 +03:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import fs from 'fs';
|
|
|
|
import path from 'path';
|
|
|
|
import zlib from 'browserify-zlib';
|
|
|
|
|
2019-11-23 15:15:06 +03:00
|
|
|
import { randomBytes, randomHexString, randomNumber } from "./random";
|
|
|
|
export { randomBytes, randomHexString, randomNumber };
|
2019-05-15 01:25:46 +03:00
|
|
|
|
|
|
|
export module TestCase {
|
2020-07-08 05:18:02 +03:00
|
|
|
export type BigNumber = {
|
|
|
|
testcase: string;
|
|
|
|
value: string | number;
|
|
|
|
expectedValue: string;
|
|
|
|
};
|
|
|
|
|
2020-07-13 15:03:56 +03:00
|
|
|
export type Hash = {
|
|
|
|
data: string;
|
|
|
|
keccak256: string;
|
|
|
|
sha256: string;
|
|
|
|
sha512: string;
|
|
|
|
};
|
|
|
|
|
2019-05-15 01:25:46 +03:00
|
|
|
export type HDWalletNode = {
|
|
|
|
path: string;
|
|
|
|
address: string;
|
|
|
|
privateKey: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type HDWallet = {
|
|
|
|
name: string;
|
|
|
|
|
|
|
|
seed: string;
|
|
|
|
locale: string;
|
|
|
|
password?: string;
|
|
|
|
entropy: string;
|
|
|
|
mnemonic: string;
|
|
|
|
|
|
|
|
hdnodes: Array<HDWalletNode>
|
|
|
|
};
|
|
|
|
|
2019-08-02 09:10:58 +03:00
|
|
|
export type Nameprep = {
|
|
|
|
comment: string;
|
|
|
|
input: Array<number>;
|
|
|
|
output: Array<number>;
|
|
|
|
rc?: string;
|
|
|
|
flags?: string;
|
|
|
|
};
|
|
|
|
|
2019-08-22 23:00:53 +03:00
|
|
|
export type Wallet = {
|
|
|
|
name: string;
|
|
|
|
type: "crowdsale" | "secret-storage";
|
|
|
|
hasAddress: boolean;
|
|
|
|
address: string;
|
|
|
|
privateKey: string;
|
|
|
|
mnemonic?: string;
|
|
|
|
password?: string;
|
|
|
|
json: string;
|
|
|
|
};
|
|
|
|
|
2019-05-15 01:25:46 +03:00
|
|
|
export type Wordlist = {
|
|
|
|
locale: string;
|
|
|
|
content: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type Unit = {
|
|
|
|
name: string
|
|
|
|
|
|
|
|
ether: string,
|
|
|
|
ether_format: string,
|
|
|
|
|
|
|
|
wei: string,
|
|
|
|
|
|
|
|
kwei?: string,
|
|
|
|
mwei?: string,
|
|
|
|
gwei?: string,
|
|
|
|
szabo?: string,
|
|
|
|
finney?: string,
|
|
|
|
satoshi?: string
|
|
|
|
|
|
|
|
kwei_format?: string,
|
|
|
|
mwei_format?: string,
|
|
|
|
gwei_format?: string,
|
|
|
|
szabo_format?: string,
|
|
|
|
finney_format?: string,
|
|
|
|
satoshi_format?: string
|
|
|
|
}
|
2020-01-11 11:34:00 +03:00
|
|
|
|
|
|
|
export type SignedTransaction = {
|
|
|
|
name: string;
|
|
|
|
accountAddress: string;
|
|
|
|
privateKey: string;
|
|
|
|
|
|
|
|
signedTransaction: string
|
|
|
|
unsignedTransaction: string;
|
|
|
|
|
|
|
|
signedTransactionChainId5: string
|
|
|
|
unsignedTransactionChainId5: string;
|
|
|
|
|
|
|
|
nonce: number;
|
|
|
|
gasLimit: string;
|
|
|
|
gasPrice: string;
|
|
|
|
to: string;
|
|
|
|
value: string;
|
|
|
|
data: string;
|
|
|
|
};
|
2019-05-15 01:25:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export function saveTests(tag: string, data: any) {
|
|
|
|
//let filename = path.resolve(__dirname, 'testcases', tag + '.json.gz');
|
2020-01-04 03:39:22 +03:00
|
|
|
let filename = path.resolve(__dirname, '../testcases', tag + '.json.gz');
|
2019-05-15 01:25:46 +03:00
|
|
|
|
|
|
|
fs.writeFileSync(filename, zlib.gzipSync(JSON.stringify(data, undefined, ' ') + '\n'));
|
|
|
|
|
|
|
|
console.log('Save testcase: ' + filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function loadTests(tag: string): any {
|
2019-08-25 09:39:20 +03:00
|
|
|
let filename = path.resolve(__dirname, '../testcases', tag + '.json.gz');
|
2019-05-15 01:25:46 +03:00
|
|
|
return JSON.parse(zlib.gunzipSync(fs.readFileSync(filename)).toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
export function loadData(filename: string): Buffer {
|
|
|
|
return fs.readFileSync(path.resolve(__dirname, filename));
|
|
|
|
}
|
|
|
|
|