Files: f51b785e3c8a0cb4cdd5b659a4410b44e414b871 / testEnvironment.js
1885 bytesRaw
1 | const Environment = require('./environment.js') |
2 | const U256 = require('./u256.js') |
3 | const Address = require('./address.js') |
4 | const Block = require('./block.js') |
5 | const ethUtil = require('ethereumjs-util') |
6 | |
7 | module.exports = class TestEnvironment extends Environment { |
8 | constructor (data) { |
9 | super() |
10 | |
11 | if (typeof data === 'string') { |
12 | data = JSON.parse(data) |
13 | } |
14 | |
15 | let self = this |
16 | |
17 | if (data.accounts) { |
18 | data.accounts.forEach((account) => { |
19 | let tmp = account[1] |
20 | self.addAccount(new Address(account[0]), { |
21 | balance: new U256(tmp.balance) |
22 | }) |
23 | }) |
24 | } |
25 | |
26 | if (data.address) { |
27 | self.address = new Address(data.address) |
28 | } |
29 | |
30 | if (data.origin) { |
31 | self.origin = new Address(data.origin) |
32 | } |
33 | |
34 | if (data.caller) { |
35 | self.caller = new Address(data.caller) |
36 | } |
37 | |
38 | if (data.callValue) { |
39 | self.callValue = new U256(data.callValue) |
40 | } |
41 | |
42 | if (data.callData) { |
43 | self.callData = Uint8Array.from(new Buffer(data.callData, 'hex')) |
44 | } |
45 | |
46 | if (data.gasPrice) { |
47 | self.gasPrice = data.gasPrice |
48 | } |
49 | |
50 | if (data.gasLeft) { |
51 | self.gasLeft = data.gasLeft |
52 | } |
53 | |
54 | if (data.block) { |
55 | let block = {} |
56 | |
57 | if (data.block.blockNumber) { |
58 | block.number = ethUtil.toBuffer(data.block.blockNumber) |
59 | } |
60 | |
61 | if (data.block.gasLimit) { |
62 | block.gasLimit = ethUtil.toBuffer(data.block.gasLimit) |
63 | } |
64 | |
65 | if (data.block.difficulty) { |
66 | block.difficulty = ethUtil.toBuffer(data.block.difficulty) |
67 | } |
68 | |
69 | if (data.block.timestamp) { |
70 | block.timestamp = ethUtil.toBuffer(data.block.timestam) |
71 | } |
72 | |
73 | if (data.block.coinbase) { |
74 | block.coinbase = ethUtil.toBuffer(data.block.coinbase) |
75 | } |
76 | |
77 | if (Object.keys(block).length > 0) { |
78 | self.block = new Block({ header: block, transactions: [], uncleHeaders: [] }) |
79 | } |
80 | } |
81 | } |
82 | } |
83 |
Built with git-ssb-web