git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: 3e30632034050031a6800119f8eebd8204b1bc98

Files: 3e30632034050031a6800119f8eebd8204b1bc98 / testEnvironment.js

1172 bytesRaw
1const Environment = require('./environment.js')
2const U256 = require('./u256.js')
3const Address = require('./address.js')
4
5module.exports = class TestEnvironment extends Environment {
6 constructor (data) {
7 super()
8
9 if (typeof data === 'string') {
10 data = JSON.parse(data)
11 }
12
13 let self = this
14
15 if (data.accounts) {
16 data.accounts.forEach((account) => {
17 let tmp = account[1]
18 self.state.set(new Address(account[0]).toString(), {
19 balance: new U256(tmp.balance)
20 })
21 })
22 }
23
24 if (data.address) {
25 self.address = new Address(data.address)
26 }
27
28 if (data.origin) {
29 self.origin = new Address(data.origin)
30 }
31
32 if (data.caller) {
33 self.caller = new Address(data.caller)
34 }
35
36 if (data.coinbase) {
37 self.coinbase = new Address(data.coinbase)
38 }
39
40 if (data.callValue) {
41 self.callValue = new U256(data.callValue)
42 }
43
44 if (data.callData) {
45 self.callData = Uint8Array.from(new Buffer(data.callData, 'hex'))
46 }
47
48 if (data.gasPrice) {
49 self.gasPrice = data.gasPrice
50 }
51
52 if (data.gasLeft) {
53 self.gasLeft = data.gasLeft
54 }
55 }
56}
57

Built with git-ssb-web