1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import * as path from 'path'
import { ethers } from "@nomiclabs/buidler"
import { ContractFactory } from 'ethers'
import { Interface } from 'ethers/lib/utils'
const getContractDefinition = (name: string): any => {
return require(path.join(__dirname, '../../../artifacts', `${name}.json`))
}
export const getContractInterface = (name: string): Interface => {
const definition = getContractDefinition(name)
return new ethers.utils.Interface(definition.abi)
}
// const ExecutionManager: ContractFactory = await ethers.getContractFactory('iOVM_ExecutionManager')
export const iEM = getContractInterface('iOVM_ExecutionManager')
// const CodeContract: ContractFactory = await ethers.getContractFactory('Helper_CodeContractForCalls')
const iCC = getContractInterface('Helper_CodeContractForCalls')
export interface TestCallGenerator {
generateCalldata(): string
generateExpectedReturnData(): string
parseActualReturnData(returned: string): any
}
export abstract class baseOVMCallTest implements TestCallGenerator {
executionManagerMethodName: string = 'EM METHOD NAME NOT SET'
arguments: any[] = []
expectedReturnValues: any[] = []
generateCalldata(): string {
return iEM.encodeFunctionData(
this.executionManagerMethodName,
this.arguments
)
}
generateExpectedReturnData(): string {
return iEM.encodeFunctionResult(
this.executionManagerMethodName,
this.expectedReturnValues
)
}
parseActualReturnData(returned: string) {
const decodedResult = iEM.decodeFunctionResult(
this.executionManagerMethodName,
returned
)
return 'call to ExeMgr.' + this.executionManagerMethodName + ' returned: \n' + decodedResult
}
}
export class ovmADDRESSTest extends baseOVMCallTest {
constructor(
expectedAddress: string
) {
super()
this.executionManagerMethodName = 'ovmADDRESS'
this.expectedReturnValues = [expectedAddress]
}
}
export class ovmCALLERTest extends baseOVMCallTest {
constructor(
expectedMsgSender: string
) {
super()
this.executionManagerMethodName = 'ovmCALLER'
this.expectedReturnValues = [expectedMsgSender]
}
}
const DEFAULT_GAS_LIMIT = 1_000_000
export class ovmCALLTest extends baseOVMCallTest {
constructor(
callee: string,
calleeTests: Array<TestCallGenerator>,
shouldCalleeSucceed: boolean = true,
gasLimit: number = DEFAULT_GAS_LIMIT
) {
super()
this.executionManagerMethodName = 'ovmCALL'
this.arguments = [
gasLimit,
callee,
iCC.encodeFunctionData(
'runSteps',
[{
callsToEM: calleeTests.map((testGenerator) => {
return testGenerator.generateCalldata()
}),
shouldRevert: !shouldCalleeSucceed
}]
)
]
this.expectedReturnValues = [
shouldCalleeSucceed,
iCC.encodeFunctionResult(
'runSteps',
[calleeTests.map((testGenerator) => {
return {
success: true, //TODO: figure out if we need this not to happen
data: testGenerator.generateExpectedReturnData()
}
})]
)
]
}
}