git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: ef9a2818017021a22cd85f062af777205c35969a

Files: ef9a2818017021a22cd85f062af777205c35969a / testEnvironment.js

1433 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 self.state.set(new Address(new Uint8Array(account[0])).toString(), account[1])
18 })
19 }
20
21 if (data.address) {
22 self.address = new Address(new Uint8Array(data.address))
23 }
24
25 if (data.origin) {
26 self.origin = new Address(new Uint8Array(data.origin))
27 }
28
29 if (data.caller) {
30 self.caller = new Address(new Uint8Array(data.caller))
31 }
32
33 if (data.coinbase) {
34 self.coinbase = new Uint8Array(data.coinbase)
35 }
36
37 if (data.callValue) {
38 self.callValue = new U256(data.callValue)
39 }
40
41 if (data.callData) {
42 self.callData = hexStr2arrayBuf(data.callData)
43 }
44
45 if (data.gasPrice) {
46 self.gasPrice = data.gasPrice
47 }
48
49 if (data.gasLimit) {
50 self.gasLimit = data.gasLimit
51 }
52 }
53}
54
55function hexStr2arrayBuf (string) {
56 const view = new Uint8Array(string.length / 2)
57 string = [...string]
58 let temp = ''
59 string.forEach((el, i) => {
60 temp += el
61 if (i % 2) {
62 view[(i + 1) / 2 - 1] = parseInt(temp, 16)
63 temp = ''
64 }
65 })
66 return view
67}
68

Built with git-ssb-web