ethers.js/packages/testcases/src.ts/browser.ts

28 lines
873 B
TypeScript
Raw Normal View History

2019-05-15 01:25:46 +03:00
'use strict';
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
2019-11-23 15:15:06 +03:00
import * as data from "./browser-fs.json";
2019-05-15 01:25:46 +03:00
2019-11-23 15:15:06 +03:00
const Cache: { [ filename: string ]: any } = { };
2019-05-15 01:25:46 +03:00
export function loadTests(tag: string): any {
let filename = 'testcases/' + tag + ".json.gz";
2019-11-23 15:15:06 +03:00
if (Cache[filename] == null) {
console.log("loading:", filename);
Cache[filename] = JSON.parse(zlib.gunzipSync(new Buffer((<any>data)[filename], "base64")).toString());
}
return Cache[filename];
2019-05-15 01:25:46 +03:00
}
export function loadData(filename: string): Buffer {
// Strip any leading relative paths (e.g. "./foo" => "foo")
filename = path.join(filename);
console.log("loading:", filename);
return new Buffer((<any>data)[filename], "base64");
}