Files: 0d9659e23045d218b41e945ebb6a50c7391a14da / testEnvironment.js
1124 bytesRaw
1 | const Environment = require('./environment.js') |
2 | |
3 | module.exports = class TestEnvironment extends Environment { |
4 | constructor (data) { |
5 | super() |
6 | |
7 | if (typeof data === 'string') { |
8 | data = JSON.parse(data) |
9 | } |
10 | |
11 | let self = this |
12 | |
13 | if (data.accounts) { |
14 | data.accounts.forEach((account) => { |
15 | self.state.set(new Uint8Array(account[0]).toString(), account[1]) |
16 | }) |
17 | } |
18 | |
19 | if (data.address) { |
20 | self.address = new Uint8Array(data.address) |
21 | } |
22 | |
23 | if (data.origin) { |
24 | self.origin = new Uint8Array(data.origin) |
25 | } |
26 | |
27 | if (data.caller) { |
28 | self.caller = new Uint8Array(data.caller) |
29 | } |
30 | |
31 | if (data.callValue) { |
32 | self.callValue = new Uint8Array(data.callValue) |
33 | } |
34 | |
35 | if (data.callData) { |
36 | self.callData = hexStr2arrayBuf(data.callData) |
37 | } |
38 | } |
39 | } |
40 | |
41 | function hexStr2arrayBuf (string) { |
42 | const ab = new ArrayBuffer(string.length / 2) |
43 | const view = new Uint8Array(ab) |
44 | string = [...string] |
45 | let temp = '' |
46 | string.forEach((el, i) => { |
47 | temp += el |
48 | if (i % 2) { |
49 | view[(i + 1) / 2 - 1] = parseInt(temp, 16) |
50 | temp = '' |
51 | } |
52 | }) |
53 | return ab |
54 | } |
55 |
Built with git-ssb-web