95 lines
2.2 KiB
TypeScript
95 lines
2.2 KiB
TypeScript
'use strict';
|
|
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
import zlib from 'browserify-zlib';
|
|
|
|
import { randomBytes, randomHexString, randomNumber } from "./random";
|
|
export { randomBytes, randomHexString, randomNumber };
|
|
|
|
export module TestCase {
|
|
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>
|
|
};
|
|
|
|
export type Nameprep = {
|
|
comment: string;
|
|
input: Array<number>;
|
|
output: Array<number>;
|
|
rc?: string;
|
|
flags?: string;
|
|
};
|
|
|
|
export type Wallet = {
|
|
name: string;
|
|
type: "crowdsale" | "secret-storage";
|
|
hasAddress: boolean;
|
|
address: string;
|
|
privateKey: string;
|
|
mnemonic?: string;
|
|
password?: string;
|
|
json: string;
|
|
};
|
|
|
|
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
|
|
}
|
|
}
|
|
|
|
export function saveTests(tag: string, data: any) {
|
|
//let filename = path.resolve(__dirname, 'testcases', tag + '.json.gz');
|
|
let filename = path.resolve(__dirname, '../testcases', tag + '.json.gz');
|
|
|
|
fs.writeFileSync(filename, zlib.gzipSync(JSON.stringify(data, undefined, ' ') + '\n'));
|
|
|
|
console.log('Save testcase: ' + filename);
|
|
}
|
|
|
|
export function loadTests(tag: string): any {
|
|
let filename = path.resolve(__dirname, '../testcases', tag + '.json.gz');
|
|
return JSON.parse(zlib.gunzipSync(fs.readFileSync(filename)).toString());
|
|
}
|
|
|
|
export function loadData(filename: string): Buffer {
|
|
return fs.readFileSync(path.resolve(__dirname, filename));
|
|
}
|
|
|