Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
954e87cd
Commit
954e87cd
authored
Sep 15, 2020
by
Kelvin Fichter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Restored old tests
parent
528f57f7
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
1239 additions
and
0 deletions
+1239
-0
OVM_ExecutionManager.opcodes.calling.spec.ts
...ager/opcodes/OVM_ExecutionManager.opcodes.calling.spec.ts
+343
-0
OVM_ExecutionManager.opcodes.code.spec.ts
...Manager/opcodes/OVM_ExecutionManager.opcodes.code.spec.ts
+387
-0
OVM_ExecutionManager.opcodes.creation.spec.ts
...ger/opcodes/OVM_ExecutionManager.opcodes.creation.spec.ts
+15
-0
OVM_ExecutionManager.opcodes.halting.spec.ts
...ager/opcodes/OVM_ExecutionManager.opcodes.halting.spec.ts
+76
-0
OVM_ExecutionManager.opcodes.storage.spec.ts
...ager/opcodes/OVM_ExecutionManager.opcodes.storage.spec.ts
+188
-0
OVM_StateManager.spec.ts
...cts/test/contracts/OVM/execution/OVM_StateManager.spec.ts
+169
-0
Proxy_Forwarder.spec.ts
...es/contracts/test/contracts/proxy/Proxy_Forwarder.spec.ts
+11
-0
Proxy_Manager.spec.ts
...ages/contracts/test/contracts/proxy/Proxy_Manager.spec.ts
+39
-0
Proxy_Resolver.spec.ts
...ges/contracts/test/contracts/proxy/Proxy_Resolver.spec.ts
+11
-0
No files found.
packages/contracts/test/contracts/OVM/execution/OVM_ExecutionManager/opcodes/OVM_ExecutionManager.opcodes.calling.spec.ts
0 → 100644
View file @
954e87cd
import
{
expect
}
from
'
../../../../../setup
'
/* External Imports */
import
{
ethers
}
from
'
@nomiclabs/buidler
'
import
{
Contract
,
ContractFactory
,
Signer
}
from
'
ethers
'
/* Internal Imports */
import
{
getProxyManager
,
MockContract
,
getMockContract
,
DUMMY_ACCOUNTS
,
setProxyTarget
,
ZERO_ADDRESS
,
fromHexString
,
toHexString
,
makeHexString
,
NULL_BYTES32
,
DUMMY_BYTES32
,
encodeRevertData
,
REVERT_FLAGS
,
NON_ZERO_ADDRESS
,
GAS_LIMIT
}
from
'
../../../../../helpers
'
describe
(
'
OVM_ExecutionManager:opcodes:calling
'
,
()
=>
{
let
signer
:
Signer
before
(
async
()
=>
{
;[
signer
]
=
await
ethers
.
getSigners
()
})
let
Proxy_Manager
:
Contract
before
(
async
()
=>
{
Proxy_Manager
=
await
getProxyManager
()
})
let
Mock__OVM_StateManager
:
MockContract
before
(
async
()
=>
{
Mock__OVM_StateManager
=
await
getMockContract
(
'
OVM_StateManager
'
)
Mock__OVM_StateManager
.
setReturnValues
(
'
getAccount
'
,
(
address
:
string
)
=>
{
return
[
{
...
DUMMY_ACCOUNTS
[
0
].
data
,
ethAddress
:
address
}
]
})
await
setProxyTarget
(
Proxy_Manager
,
'
OVM_StateManager
'
,
Mock__OVM_StateManager
)
})
let
Factory__OVM_ExecutionManager
:
ContractFactory
before
(
async
()
=>
{
Factory__OVM_ExecutionManager
=
await
ethers
.
getContractFactory
(
'
OVM_ExecutionManager
'
)
})
let
OVM_ExecutionManager
:
Contract
beforeEach
(
async
()
=>
{
OVM_ExecutionManager
=
await
Factory__OVM_ExecutionManager
.
deploy
(
Proxy_Manager
.
address
)
})
let
Helper_CallTarget
:
Contract
let
Helper_RevertDataViewer
:
Contract
beforeEach
(
async
()
=>
{
const
Factory__Helper_CallTarget
=
await
ethers
.
getContractFactory
(
'
Helper_CallTarget
'
)
const
Factory__Helper_RevertDataViewer
=
await
ethers
.
getContractFactory
(
'
Helper_RevertDataViewer
'
)
Helper_CallTarget
=
await
Factory__Helper_CallTarget
.
deploy
()
Helper_RevertDataViewer
=
await
Factory__Helper_RevertDataViewer
.
deploy
(
Helper_CallTarget
.
address
)
})
describe
(
'
ovmCALL
'
,
()
=>
{
describe
(
'
when the OVM_StateManager has the corresponding account
'
,
()
=>
{
before
(()
=>
{
Mock__OVM_StateManager
.
setReturnValues
(
'
hasAccount
'
,
[
true
])
})
describe
(
'
when the OVM_StateManager has already loaded the account
'
,
()
=>
{
before
(()
=>
{
Mock__OVM_StateManager
.
setReturnValues
(
'
testAndSetAccountLoaded
'
,
[
true
])
})
describe
(
'
when the call does not revert
'
,
()
=>
{
it
(
'
should return the result provided by the target contract
'
,
async
()
=>
{
const
returnData
=
makeHexString
(
'
1234
'
,
32
)
expect
(
await
OVM_ExecutionManager
.
callStatic
.
ovmCALL
(
GAS_LIMIT
,
Helper_CallTarget
.
address
,
Helper_CallTarget
.
interface
.
encodeFunctionData
(
'
doReturn
'
,
[
returnData
]
)
)
).
to
.
deep
.
equal
([
true
,
returnData
])
})
it
(
'
should set the ovmADDRESS to the target address
'
,
async
()
=>
{
expect
(
await
OVM_ExecutionManager
.
callStatic
.
ovmCALL
(
GAS_LIMIT
,
Helper_CallTarget
.
address
,
Helper_CallTarget
.
interface
.
encodeFunctionData
(
'
doReturnADDRESS
'
,
)
)
).
to
.
deep
.
equal
([
true
,
ethers
.
utils
.
defaultAbiCoder
.
encode
(
[
'
address
'
],
[
Helper_CallTarget
.
address
]
)
])
})
})
describe
(
'
when the call does revert
'
,
()
=>
{
describe
(
'
with no data
'
,
()
=>
{
it
(
'
should return false with no data
'
,
async
()
=>
{
expect
(
await
OVM_ExecutionManager
.
callStatic
.
ovmCALL
(
GAS_LIMIT
,
Helper_CallTarget
.
address
,
Helper_CallTarget
.
interface
.
encodeFunctionData
(
'
doRevert
'
,
[
'
0x
'
]
)
)
).
to
.
deep
.
equal
([
false
,
'
0x
'
])
})
})
describe
(
'
with the INTENTIONAL_REVERT flag
'
,
()
=>
{
it
(
'
should return false with the flag and user-provided data
'
,
async
()
=>
{
})
})
describe
(
'
with the EXCEEDS_NUISANCE_GAS flag
'
,
()
=>
{
it
(
'
should return false with the flag
'
,
async
()
=>
{
})
})
describe
(
'
with the INVALID_STATE_ACCESS flag
'
,
()
=>
{
it
(
'
should revert with the INVALID_STATE_ACCESS flag
'
,
()
=>
{
})
})
describe
(
'
with the UNSAFE_BYTECODE flag
'
,
()
=>
{
it
(
'
should return false with the flag and no data
'
,
async
()
=>
{
})
})
})
})
describe
(
'
when the OVM_StateManager has not already loaded the account
'
,
()
=>
{
before
(()
=>
{
Mock__OVM_StateManager
.
setReturnValues
(
'
testAndSetAccountLoaded
'
,
[
false
])
})
describe
(
'
when the call parent does not contain enough nuisance gas
'
,
()
=>
{
it
(
'
should revert with the EXCEEDS_NUISANCE_GAS flag
'
,
()
=>
{
})
})
})
})
describe
(
'
when the OVM_StateManager does not have the corresponding account
'
,
()
=>
{
before
(()
=>
{
Mock__OVM_StateManager
.
setReturnValues
(
'
hasAccount
'
,
[
false
])
})
it
(
'
should revert with the INVALID_STATE_ACCESS flag
'
,
()
=>
{
})
})
})
describe
(
'
ovmSTATICCALL
'
,
()
=>
{
describe
(
'
when the OVM_StateManager has the corresponding account
'
,
()
=>
{
before
(()
=>
{
Mock__OVM_StateManager
.
setReturnValues
(
'
hasAccount
'
,
[
true
])
})
describe
(
'
when the OVM_StateManager has already loaded the account
'
,
()
=>
{
before
(()
=>
{
Mock__OVM_StateManager
.
setReturnValues
(
'
testAndSetAccountLoaded
'
,
[
true
])
})
describe
(
'
when the call does not revert
'
,
()
=>
{
it
(
'
should return the result provided by the target contract
'
,
async
()
=>
{
})
it
(
'
should set the context to static
'
,
async
()
=>
{
})
})
describe
(
'
when the call does revert
'
,
()
=>
{
describe
(
'
with no data
'
,
()
=>
{
it
(
'
should return false with no data
'
,
async
()
=>
{
})
})
describe
(
'
with the INTENTIONAL_REVERT flag
'
,
()
=>
{
it
(
'
should return false with the flag and user-provided data
'
,
async
()
=>
{
})
})
describe
(
'
with the EXCEEDS_NUISANCE_GAS flag
'
,
()
=>
{
it
(
'
should return false with the flag
'
,
async
()
=>
{
})
})
describe
(
'
with the INVALID_STATE_ACCESS flag
'
,
()
=>
{
it
(
'
should revert with the INVALID_STATE_ACCESS flag
'
,
()
=>
{
})
})
describe
(
'
with the UNSAFE_BYTECODE flag
'
,
()
=>
{
it
(
'
should return false with the flag and no data
'
,
async
()
=>
{
})
})
})
})
describe
(
'
when the OVM_StateManager has not already loaded the account
'
,
()
=>
{
before
(()
=>
{
Mock__OVM_StateManager
.
setReturnValues
(
'
testAndSetAccountLoaded
'
,
[
false
])
})
describe
(
'
when the call parent does not contain enough nuisance gas
'
,
()
=>
{
it
(
'
should revert with the EXCEEDS_NUISANCE_GAS flag
'
,
()
=>
{
})
})
})
})
describe
(
'
when the OVM_StateManager does not have the corresponding account
'
,
()
=>
{
before
(()
=>
{
Mock__OVM_StateManager
.
setReturnValues
(
'
hasAccount
'
,
[
false
])
})
it
(
'
should revert with the INVALID_STATE_ACCESS flag
'
,
()
=>
{
})
})
})
describe
(
'
ovmDELEGATECALL
'
,
()
=>
{
describe
(
'
when the OVM_StateManager has the corresponding account
'
,
()
=>
{
before
(()
=>
{
Mock__OVM_StateManager
.
setReturnValues
(
'
hasAccount
'
,
[
true
])
})
describe
(
'
when the OVM_StateManager has already loaded the account
'
,
()
=>
{
before
(()
=>
{
Mock__OVM_StateManager
.
setReturnValues
(
'
testAndSetAccountLoaded
'
,
[
true
])
})
describe
(
'
when the call does not revert
'
,
()
=>
{
it
(
'
should return the result provided by the target contract
'
,
async
()
=>
{
})
it
(
'
should retain the previous ovmADDRESS
'
,
async
()
=>
{
})
})
describe
(
'
when the call does revert
'
,
()
=>
{
describe
(
'
with no data
'
,
()
=>
{
it
(
'
should return false with no data
'
,
async
()
=>
{
})
})
describe
(
'
with the INTENTIONAL_REVERT flag
'
,
()
=>
{
it
(
'
should return false with the flag and user-provided data
'
,
async
()
=>
{
})
})
describe
(
'
with the EXCEEDS_NUISANCE_GAS flag
'
,
()
=>
{
it
(
'
should return false with the flag
'
,
async
()
=>
{
})
})
describe
(
'
with the INVALID_STATE_ACCESS flag
'
,
()
=>
{
it
(
'
should revert with the INVALID_STATE_ACCESS flag
'
,
()
=>
{
})
})
describe
(
'
with the UNSAFE_BYTECODE flag
'
,
()
=>
{
it
(
'
should return false with the flag and no data
'
,
async
()
=>
{
})
})
})
})
describe
(
'
when the OVM_StateManager has not already loaded the account
'
,
()
=>
{
before
(()
=>
{
Mock__OVM_StateManager
.
setReturnValues
(
'
testAndSetAccountLoaded
'
,
[
false
])
})
describe
(
'
when the call parent does not contain enough nuisance gas
'
,
()
=>
{
it
(
'
should revert with the EXCEEDS_NUISANCE_GAS flag
'
,
()
=>
{
})
})
})
})
describe
(
'
when the OVM_StateManager does not have the corresponding account
'
,
()
=>
{
before
(()
=>
{
Mock__OVM_StateManager
.
setReturnValues
(
'
hasAccount
'
,
[
false
])
})
it
(
'
should revert with the INVALID_STATE_ACCESS flag
'
,
()
=>
{
})
})
})
})
packages/contracts/test/contracts/OVM/execution/OVM_ExecutionManager/opcodes/OVM_ExecutionManager.opcodes.code.spec.ts
0 → 100644
View file @
954e87cd
import
{
expect
}
from
'
../../../../../setup
'
/* External Imports */
import
{
ethers
}
from
'
@nomiclabs/buidler
'
import
{
Contract
,
ContractFactory
}
from
'
ethers
'
/* Internal Imports */
import
{
getProxyManager
,
MockContract
,
getMockContract
,
DUMMY_ACCOUNTS
,
setProxyTarget
,
ZERO_ADDRESS
,
fromHexString
,
toHexString
,
makeHexString
,
NULL_BYTES32
,
DUMMY_BYTES32
,
encodeRevertData
,
REVERT_FLAGS
}
from
'
../../../../../helpers
'
describe
(
'
OVM_ExecutionManager:opcodes:code
'
,
()
=>
{
let
Proxy_Manager
:
Contract
before
(
async
()
=>
{
Proxy_Manager
=
await
getProxyManager
()
})
let
Mock__OVM_StateManager
:
MockContract
before
(
async
()
=>
{
Mock__OVM_StateManager
=
await
getMockContract
(
'
OVM_StateManager
'
)
Mock__OVM_StateManager
.
setReturnValues
(
'
getAccount
'
,
(
address
:
string
)
=>
{
return
[
{
...
DUMMY_ACCOUNTS
[
0
].
data
,
ethAddress
:
address
}
]
})
await
setProxyTarget
(
Proxy_Manager
,
'
OVM_StateManager
'
,
Mock__OVM_StateManager
)
})
let
Dummy_Contract
:
Contract
before
(
async
()
=>
{
// We need some contract to query code for, might as well reuse an existing object.
Dummy_Contract
=
Mock__OVM_StateManager
})
let
Factory__OVM_ExecutionManager
:
ContractFactory
before
(
async
()
=>
{
Factory__OVM_ExecutionManager
=
await
ethers
.
getContractFactory
(
'
OVM_ExecutionManager
'
)
})
let
OVM_ExecutionManager
:
Contract
beforeEach
(
async
()
=>
{
OVM_ExecutionManager
=
await
Factory__OVM_ExecutionManager
.
deploy
(
Proxy_Manager
.
address
)
})
let
Helper_RevertDataViewer
:
Contract
beforeEach
(
async
()
=>
{
const
Factory__Helper_RevertDataViewer
=
await
ethers
.
getContractFactory
(
'
Helper_RevertDataViewer
'
)
Helper_RevertDataViewer
=
await
Factory__Helper_RevertDataViewer
.
deploy
(
OVM_ExecutionManager
.
address
)
})
describe
(
'
ovmEXTCODECOPY()
'
,
()
=>
{
describe
(
'
when the OVM_StateManager has the corresponding account
'
,
()
=>
{
before
(()
=>
{
Mock__OVM_StateManager
.
setReturnValues
(
'
hasAccount
'
,
[
true
])
})
describe
(
'
when the OVM_StateManager has already loaded the corresponding account
'
,
()
=>
{
before
(()
=>
{
Mock__OVM_StateManager
.
setReturnValues
(
'
testAndSetAccountLoaded
'
,
[
true
])
})
it
(
'
should return the code for a given account
'
,
async
()
=>
{
const
expectedCode
=
await
ethers
.
provider
.
getCode
(
Dummy_Contract
.
address
)
const
expectedCodeSize
=
fromHexString
(
expectedCode
).
length
expect
(
await
OVM_ExecutionManager
.
callStatic
.
ovmEXTCODECOPY
(
Dummy_Contract
.
address
,
0
,
expectedCodeSize
)
).
to
.
equal
(
expectedCode
)
})
it
(
'
should return empty if the provided length is zero
'
,
async
()
=>
{
const
expectedCode
=
'
0x
'
expect
(
await
OVM_ExecutionManager
.
callStatic
.
ovmEXTCODECOPY
(
Dummy_Contract
.
address
,
0
,
0
)
).
to
.
equal
(
expectedCode
)
})
it
(
'
should return offset code when offset is less than total length
'
,
async
()
=>
{
const
fullCode
=
await
ethers
.
provider
.
getCode
(
Dummy_Contract
.
address
)
const
fullCodeSize
=
fromHexString
(
fullCode
).
length
const
codeOffset
=
Math
.
floor
(
fullCodeSize
/
2
)
const
codeLength
=
fullCodeSize
-
codeOffset
const
expectedCode
=
toHexString
(
fromHexString
(
fullCode
).
slice
(
codeOffset
,
codeOffset
+
codeLength
))
expect
(
await
OVM_ExecutionManager
.
callStatic
.
ovmEXTCODECOPY
(
Dummy_Contract
.
address
,
codeOffset
,
codeLength
)
).
to
.
equal
(
expectedCode
)
})
it
(
'
should return less code when length is less than total length
'
,
async
()
=>
{
const
fullCode
=
await
ethers
.
provider
.
getCode
(
Dummy_Contract
.
address
)
const
fullCodeSize
=
fromHexString
(
fullCode
).
length
const
codeLength
=
Math
.
floor
(
fullCodeSize
/
2
)
const
expectedCode
=
toHexString
(
fromHexString
(
fullCode
).
slice
(
0
,
codeLength
))
expect
(
await
OVM_ExecutionManager
.
callStatic
.
ovmEXTCODECOPY
(
Dummy_Contract
.
address
,
0
,
codeLength
)
).
to
.
equal
(
expectedCode
)
})
it
(
'
should return extra code when length is greater than total length
'
,
async
()
=>
{
const
fullCode
=
await
ethers
.
provider
.
getCode
(
Dummy_Contract
.
address
)
const
fullCodeSize
=
fromHexString
(
fullCode
).
length
const
extraLength
=
fullCodeSize
const
codeLength
=
fullCodeSize
+
extraLength
const
expectedCode
=
toHexString
(
Buffer
.
concat
([
fromHexString
(
fullCode
),
fromHexString
(
makeHexString
(
'
00
'
,
extraLength
))
]))
expect
(
await
OVM_ExecutionManager
.
callStatic
.
ovmEXTCODECOPY
(
Dummy_Contract
.
address
,
0
,
codeLength
)
).
to
.
equal
(
expectedCode
)
})
it
(
'
should return extra code when offset is less than total length and length is greater than total length
'
,
async
()
=>
{
const
fullCode
=
await
ethers
.
provider
.
getCode
(
Dummy_Contract
.
address
)
const
fullCodeSize
=
fromHexString
(
fullCode
).
length
const
extraLength
=
fullCodeSize
const
codeOffset
=
Math
.
floor
(
fullCodeSize
/
2
)
const
codeLength
=
fullCodeSize
-
codeOffset
+
extraLength
const
expectedCode
=
toHexString
(
Buffer
.
concat
([
fromHexString
(
fullCode
).
slice
(
codeOffset
,
codeOffset
+
codeLength
),
fromHexString
(
makeHexString
(
'
00
'
,
extraLength
))
]))
expect
(
await
OVM_ExecutionManager
.
callStatic
.
ovmEXTCODECOPY
(
Dummy_Contract
.
address
,
codeOffset
,
codeLength
)
).
to
.
equal
(
expectedCode
)
})
it
(
'
should return empty bytes when both offset and length exceed total length
'
,
async
()
=>
{
const
fullCode
=
await
ethers
.
provider
.
getCode
(
Dummy_Contract
.
address
)
const
fullCodeSize
=
fromHexString
(
fullCode
).
length
const
extraLength
=
fullCodeSize
const
codeOffset
=
fullCodeSize
const
codeLength
=
fullCodeSize
+
extraLength
const
expectedCode
=
toHexString
(
Buffer
.
concat
([
fromHexString
(
makeHexString
(
'
00
'
,
codeLength
))
]))
expect
(
await
OVM_ExecutionManager
.
callStatic
.
ovmEXTCODECOPY
(
Dummy_Contract
.
address
,
codeOffset
,
codeLength
)
).
to
.
equal
(
expectedCode
)
})
})
describe
(
'
when the OVM_StateManager has not already loaded the corresponding account
'
,
()
=>
{
before
(()
=>
{
Mock__OVM_StateManager
.
setReturnValues
(
'
testAndSetAccountLoaded
'
,
[
false
])
})
it
(
'
should revert with the EXCEEDS_NUISANCE_GAS flag
'
,
async
()
=>
{
const
calldata
=
OVM_ExecutionManager
.
interface
.
encodeFunctionData
(
'
ovmEXTCODECOPY
'
,
[
Dummy_Contract
.
address
,
0
,
0
]
)
await
Helper_RevertDataViewer
.
fallback
({
data
:
calldata
})
expect
(
await
Helper_RevertDataViewer
.
revertdata
()
).
to
.
equal
(
encodeRevertData
(
REVERT_FLAGS
.
EXCEEDS_NUISANCE_GAS
))
})
})
})
describe
(
'
when the OVM_StateManager does not have the corresponding account
'
,
()
=>
{
before
(()
=>
{
Mock__OVM_StateManager
.
setReturnValues
(
'
hasAccount
'
,
[
false
])
})
it
(
'
should revert with the INVALID_STATE_ACCESS flag
'
,
async
()
=>
{
const
calldata
=
OVM_ExecutionManager
.
interface
.
encodeFunctionData
(
'
ovmEXTCODECOPY
'
,
[
Dummy_Contract
.
address
,
0
,
0
]
)
await
Helper_RevertDataViewer
.
fallback
({
data
:
calldata
})
expect
(
await
Helper_RevertDataViewer
.
revertdata
()
).
to
.
equal
(
encodeRevertData
(
REVERT_FLAGS
.
INVALID_STATE_ACCESS
))
})
})
})
describe
(
'
ovmEXTCODESIZE()
'
,
()
=>
{
describe
(
'
when the OVM_StateManager has the corresponding account
'
,
()
=>
{
before
(()
=>
{
Mock__OVM_StateManager
.
setReturnValues
(
'
hasAccount
'
,
[
true
])
})
describe
(
'
when the OVM_StateManager has already loaded the corresponding account
'
,
()
=>
{
before
(()
=>
{
Mock__OVM_StateManager
.
setReturnValues
(
'
testAndSetAccountLoaded
'
,
[
true
])
})
it
(
'
should return the code size for a given account
'
,
async
()
=>
{
const
expectedCode
=
await
ethers
.
provider
.
getCode
(
Dummy_Contract
.
address
)
const
expectedCodeSize
=
fromHexString
(
expectedCode
).
length
expect
(
await
OVM_ExecutionManager
.
callStatic
.
ovmEXTCODESIZE
(
Dummy_Contract
.
address
)
).
to
.
equal
(
expectedCodeSize
)
})
it
(
'
should return zero if the account has no code
'
,
async
()
=>
{
const
expectedCodeSize
=
0
expect
(
await
OVM_ExecutionManager
.
callStatic
.
ovmEXTCODESIZE
(
ZERO_ADDRESS
)
).
to
.
equal
(
expectedCodeSize
)
})
})
describe
(
'
when the OVM_StateManager has not already loaded the corresponding account
'
,
()
=>
{
before
(()
=>
{
Mock__OVM_StateManager
.
setReturnValues
(
'
testAndSetAccountLoaded
'
,
[
false
])
})
it
(
'
should revert with the EXCEEDS_NUISANCE_GAS flag
'
,
async
()
=>
{
const
calldata
=
OVM_ExecutionManager
.
interface
.
encodeFunctionData
(
'
ovmEXTCODESIZE
'
,
[
Dummy_Contract
.
address
,
]
)
await
Helper_RevertDataViewer
.
fallback
({
data
:
calldata
})
expect
(
await
Helper_RevertDataViewer
.
revertdata
()
).
to
.
equal
(
encodeRevertData
(
REVERT_FLAGS
.
EXCEEDS_NUISANCE_GAS
))
})
})
})
describe
(
'
when the OVM_StateManager does not have the corresponding account
'
,
()
=>
{
before
(()
=>
{
Mock__OVM_StateManager
.
setReturnValues
(
'
hasAccount
'
,
[
false
])
})
it
(
'
should revert with the INVALID_STATE_ACCESS flag
'
,
async
()
=>
{
const
calldata
=
OVM_ExecutionManager
.
interface
.
encodeFunctionData
(
'
ovmEXTCODESIZE
'
,
[
Dummy_Contract
.
address
]
)
await
Helper_RevertDataViewer
.
fallback
({
data
:
calldata
})
expect
(
await
Helper_RevertDataViewer
.
revertdata
()
).
to
.
equal
(
encodeRevertData
(
REVERT_FLAGS
.
INVALID_STATE_ACCESS
))
})
})
})
describe
(
'
ovmEXTCODEHASH()
'
,
()
=>
{
describe
(
'
when the OVM_StateManager has the corresponding account
'
,
()
=>
{
before
(()
=>
{
Mock__OVM_StateManager
.
setReturnValues
(
'
hasAccount
'
,
[
true
])
})
describe
(
'
when the OVM_StateManager has already loaded the corresponding account
'
,
()
=>
{
before
(()
=>
{
Mock__OVM_StateManager
.
setReturnValues
(
'
testAndSetAccountLoaded
'
,
[
true
])
})
it
(
'
should return the code hash for a given account
'
,
async
()
=>
{
const
expectedCode
=
await
ethers
.
provider
.
getCode
(
Dummy_Contract
.
address
)
const
expectedCodeHash
=
ethers
.
utils
.
keccak256
(
expectedCode
)
expect
(
await
OVM_ExecutionManager
.
callStatic
.
ovmEXTCODEHASH
(
Dummy_Contract
.
address
)
).
to
.
equal
(
expectedCodeHash
)
})
it
(
'
should return zero if the account does not exist
'
,
async
()
=>
{
const
expectedCodeHash
=
NULL_BYTES32
expect
(
await
OVM_ExecutionManager
.
callStatic
.
ovmEXTCODEHASH
(
ZERO_ADDRESS
)
).
to
.
equal
(
expectedCodeHash
)
})
})
describe
(
'
when the OVM_StateManager has not already loaded the corresponding account
'
,
()
=>
{
before
(()
=>
{
Mock__OVM_StateManager
.
setReturnValues
(
'
testAndSetAccountLoaded
'
,
[
false
])
})
it
(
'
should revert with the EXCEEDS_NUISANCE_GAS flag
'
,
async
()
=>
{
const
calldata
=
OVM_ExecutionManager
.
interface
.
encodeFunctionData
(
'
ovmEXTCODEHASH
'
,
[
Dummy_Contract
.
address
,
]
)
await
Helper_RevertDataViewer
.
fallback
({
data
:
calldata
})
expect
(
await
Helper_RevertDataViewer
.
revertdata
()
).
to
.
equal
(
encodeRevertData
(
REVERT_FLAGS
.
EXCEEDS_NUISANCE_GAS
))
})
})
})
describe
(
'
when the OVM_StateManager does not have the corresponding account
'
,
()
=>
{
before
(()
=>
{
Mock__OVM_StateManager
.
setReturnValues
(
'
hasAccount
'
,
[
false
])
})
it
(
'
should revert with the INVALID_STATE_ACCESS flag
'
,
async
()
=>
{
const
calldata
=
OVM_ExecutionManager
.
interface
.
encodeFunctionData
(
'
ovmEXTCODEHASH
'
,
[
Dummy_Contract
.
address
]
)
await
Helper_RevertDataViewer
.
fallback
({
data
:
calldata
})
expect
(
await
Helper_RevertDataViewer
.
revertdata
()
).
to
.
equal
(
encodeRevertData
(
REVERT_FLAGS
.
INVALID_STATE_ACCESS
))
})
})
})
})
packages/contracts/test/contracts/OVM/execution/OVM_ExecutionManager/opcodes/OVM_ExecutionManager.opcodes.creation.spec.ts
0 → 100644
View file @
954e87cd
import
{
expect
}
from
'
../../../../../setup
'
/* External Imports */
import
{
ethers
}
from
'
@nomiclabs/buidler
'
import
{
Contract
,
ContractFactory
}
from
'
ethers
'
describe
(
'
OVM_ExecutionManager:opcodes:creation
'
,
()
=>
{
describe
(
'
ovmCREATE
'
,
()
=>
{
})
describe
(
'
ovmCREATE2
'
,
()
=>
{
})
})
packages/contracts/test/contracts/OVM/execution/OVM_ExecutionManager/opcodes/OVM_ExecutionManager.opcodes.halting.spec.ts
0 → 100644
View file @
954e87cd
import
{
expect
}
from
'
../../../../../setup
'
/* External Imports */
import
{
ethers
}
from
'
@nomiclabs/buidler
'
import
{
Contract
,
ContractFactory
}
from
'
ethers
'
/* Internal Imports */
import
{
getProxyManager
,
encodeRevertData
,
REVERT_FLAGS
}
from
'
../../../../../helpers
'
describe
(
'
OVM_ExecutionManager:opcodes:halting
'
,
()
=>
{
let
Proxy_Manager
:
Contract
before
(
async
()
=>
{
Proxy_Manager
=
await
getProxyManager
()
})
let
Factory__OVM_ExecutionManager
:
ContractFactory
before
(
async
()
=>
{
Factory__OVM_ExecutionManager
=
await
ethers
.
getContractFactory
(
'
OVM_ExecutionManager
'
)
})
let
OVM_ExecutionManager
:
Contract
beforeEach
(
async
()
=>
{
OVM_ExecutionManager
=
await
Factory__OVM_ExecutionManager
.
deploy
(
Proxy_Manager
.
address
)
})
let
Helper_RevertDataViewer
:
Contract
beforeEach
(
async
()
=>
{
const
Factory__Helper_RevertDataViewer
=
await
ethers
.
getContractFactory
(
'
Helper_RevertDataViewer
'
)
Helper_RevertDataViewer
=
await
Factory__Helper_RevertDataViewer
.
deploy
(
OVM_ExecutionManager
.
address
)
})
describe
(
'
ovmREVERT
'
,
()
=>
{
it
(
'
should revert with the provided data prefixed by the intentional revert flag
'
,
async
()
=>
{
const
revertdata
=
'
12345678
'
.
repeat
(
10
)
const
calldata
=
OVM_ExecutionManager
.
interface
.
encodeFunctionData
(
'
ovmREVERT
'
,
[
'
0x
'
+
revertdata
]
)
await
Helper_RevertDataViewer
.
fallback
({
data
:
calldata
})
expect
(
await
Helper_RevertDataViewer
.
revertdata
()
).
to
.
equal
(
encodeRevertData
(
REVERT_FLAGS
.
INTENTIONAL_REVERT
,
'
0x
'
+
revertdata
))
})
it
(
'
should revert with the intentional revert flag if no data is provided
'
,
async
()
=>
{
const
calldata
=
OVM_ExecutionManager
.
interface
.
encodeFunctionData
(
'
ovmREVERT
'
,
[
'
0x
'
]
)
await
Helper_RevertDataViewer
.
fallback
({
data
:
calldata
})
expect
(
await
Helper_RevertDataViewer
.
revertdata
()
).
to
.
equal
(
encodeRevertData
(
REVERT_FLAGS
.
INTENTIONAL_REVERT
))
})
})
})
packages/contracts/test/contracts/OVM/execution/OVM_ExecutionManager/opcodes/OVM_ExecutionManager.opcodes.storage.spec.ts
0 → 100644
View file @
954e87cd
import
{
expect
}
from
'
../../../../../setup
'
/* External Imports */
import
{
ethers
}
from
'
@nomiclabs/buidler
'
import
{
Contract
,
ContractFactory
}
from
'
ethers
'
/* Internal Imports */
import
{
getProxyManager
,
MockContract
,
getMockContract
,
DUMMY_ACCOUNTS
,
setProxyTarget
,
ZERO_ADDRESS
,
fromHexString
,
toHexString
,
makeHexString
,
NULL_BYTES32
,
DUMMY_BYTES32
,
encodeRevertData
,
REVERT_FLAGS
,
NON_ZERO_ADDRESS
}
from
'
../../../../../helpers
'
describe
(
'
OVM_ExecutionManager:opcodes:storage
'
,
()
=>
{
let
Proxy_Manager
:
Contract
before
(
async
()
=>
{
Proxy_Manager
=
await
getProxyManager
()
})
let
Mock__OVM_StateManager
:
MockContract
before
(
async
()
=>
{
Mock__OVM_StateManager
=
await
getMockContract
(
'
OVM_StateManager
'
)
await
setProxyTarget
(
Proxy_Manager
,
'
OVM_StateManager
'
,
Mock__OVM_StateManager
)
})
let
Factory__OVM_ExecutionManager
:
ContractFactory
before
(
async
()
=>
{
Factory__OVM_ExecutionManager
=
await
ethers
.
getContractFactory
(
'
OVM_ExecutionManager
'
)
})
let
OVM_ExecutionManager
:
Contract
beforeEach
(
async
()
=>
{
OVM_ExecutionManager
=
await
Factory__OVM_ExecutionManager
.
deploy
(
Proxy_Manager
.
address
)
})
let
Helper_RevertDataViewer
:
Contract
beforeEach
(
async
()
=>
{
const
Factory__Helper_RevertDataViewer
=
await
ethers
.
getContractFactory
(
'
Helper_RevertDataViewer
'
)
Helper_RevertDataViewer
=
await
Factory__Helper_RevertDataViewer
.
deploy
(
OVM_ExecutionManager
.
address
)
})
const
DUMMY_SLOT_KEY
=
DUMMY_BYTES32
[
0
]
const
DUMMY_SLOT_VALUE
=
DUMMY_BYTES32
[
1
]
describe
(
'
ovmSLOAD
'
,
()
=>
{
before
(()
=>
{
Mock__OVM_StateManager
.
setReturnValues
(
'
getContractStorage
'
,
()
=>
{
return
[
DUMMY_SLOT_VALUE
]
})
})
describe
(
'
when the OVM_StateManager has the corresponding storage slot
'
,
()
=>
{
before
(()
=>
{
Mock__OVM_StateManager
.
setReturnValues
(
'
hasContractStorage
'
,
[
true
])
})
describe
(
'
when the OVM_StateManager has already loaded the storage slot
'
,
()
=>
{
before
(()
=>
{
Mock__OVM_StateManager
.
setReturnValues
(
'
testAndSetContractStorageLoaded
'
,
[
true
])
})
it
(
'
should return the value of the storage slot
'
,
async
()
=>
{
expect
(
await
OVM_ExecutionManager
.
callStatic
.
ovmSLOAD
(
DUMMY_SLOT_KEY
)
).
to
.
equal
(
DUMMY_SLOT_VALUE
)
})
})
describe
(
'
when the OVM_StateManager has not already loaded the storage slot
'
,
()
=>
{
before
(()
=>
{
Mock__OVM_StateManager
.
setReturnValues
(
'
testAndSetContractStorageLoaded
'
,
[
false
])
})
it
(
'
should revert with the EXCEEDS_NUISANCE_GAS flag
'
,
async
()
=>
{
const
calldata
=
OVM_ExecutionManager
.
interface
.
encodeFunctionData
(
'
ovmSLOAD
'
,
[
DUMMY_SLOT_KEY
]
)
await
Helper_RevertDataViewer
.
fallback
({
data
:
calldata
})
expect
(
await
Helper_RevertDataViewer
.
revertdata
()
).
to
.
equal
(
encodeRevertData
(
REVERT_FLAGS
.
EXCEEDS_NUISANCE_GAS
))
})
})
})
describe
(
'
when the OVM_StateManager does not have the corresponding storage slot
'
,
()
=>
{
before
(()
=>
{
Mock__OVM_StateManager
.
setReturnValues
(
'
hasContractStorage
'
,
[
false
])
})
it
(
'
should revert with the INVALID_STATE_ACCESS flag
'
,
async
()
=>
{
const
calldata
=
OVM_ExecutionManager
.
interface
.
encodeFunctionData
(
'
ovmSLOAD
'
,
[
DUMMY_SLOT_KEY
]
)
await
Helper_RevertDataViewer
.
fallback
({
data
:
calldata
})
expect
(
await
Helper_RevertDataViewer
.
revertdata
()
).
to
.
equal
(
encodeRevertData
(
REVERT_FLAGS
.
INVALID_STATE_ACCESS
))
})
})
})
describe
(
'
ovmSSTORE
'
,
()
=>
{
describe
(
'
when the OVM_StateManager has already changed the storage slot
'
,
()
=>
{
before
(()
=>
{
Mock__OVM_StateManager
.
setReturnValues
(
'
testAndSetContractStorageChanged
'
,
[
true
])
})
it
(
'
should modify the storage slot value
'
,
async
()
=>
{
await
expect
(
OVM_ExecutionManager
.
ovmSSTORE
(
DUMMY_SLOT_KEY
,
DUMMY_SLOT_VALUE
)
).
to
.
not
.
be
.
reverted
expect
(
Mock__OVM_StateManager
.
getCallData
(
'
putContractStorage
'
,
0
)
).
to
.
deep
.
equal
(
[
ZERO_ADDRESS
,
DUMMY_SLOT_KEY
,
DUMMY_SLOT_VALUE
]
)
})
})
describe
(
'
when the OVM_StateManager has not already changed the storage slot
'
,
()
=>
{
before
(()
=>
{
Mock__OVM_StateManager
.
setReturnValues
(
'
testAndSetContractStorageChanged
'
,
[
false
])
})
it
(
'
should revert with the EXCEEDS_NUISANCE_GAS flag
'
,
async
()
=>
{
const
calldata
=
OVM_ExecutionManager
.
interface
.
encodeFunctionData
(
'
ovmSSTORE
'
,
[
DUMMY_SLOT_KEY
,
DUMMY_SLOT_VALUE
]
)
await
Helper_RevertDataViewer
.
fallback
({
data
:
calldata
})
expect
(
await
Helper_RevertDataViewer
.
revertdata
()
).
to
.
equal
(
encodeRevertData
(
REVERT_FLAGS
.
EXCEEDS_NUISANCE_GAS
))
})
})
})
})
packages/contracts/test/contracts/OVM/execution/OVM_StateManager.spec.ts
0 → 100644
View file @
954e87cd
import
{
expect
}
from
'
../../../setup
'
/* External Imports */
import
{
ethers
}
from
'
@nomiclabs/buidler
'
import
{
Contract
,
ContractFactory
}
from
'
ethers
'
/* Internal Imports */
import
{
DUMMY_ACCOUNTS
,
DUMMY_BYTES32
,
toOVMAccount
}
from
'
../../../helpers
'
describe
(
'
OVM_StateManager
'
,
()
=>
{
let
Factory__OVM_StateManager
:
ContractFactory
before
(
async
()
=>
{
Factory__OVM_StateManager
=
await
ethers
.
getContractFactory
(
'
OVM_StateManager
'
)
})
let
OVM_StateManager
:
Contract
beforeEach
(
async
()
=>
{
OVM_StateManager
=
await
Factory__OVM_StateManager
.
deploy
()
})
describe
(
'
putAccount
'
,
()
=>
{
it
(
'
should be able to store an OVM account
'
,
async
()
=>
{
await
expect
(
OVM_StateManager
.
putAccount
(
DUMMY_ACCOUNTS
[
0
].
address
,
DUMMY_ACCOUNTS
[
0
].
data
)
).
to
.
not
.
be
.
reverted
})
it
(
'
should be able to overwrite an OVM account
'
,
async
()
=>
{
await
OVM_StateManager
.
putAccount
(
DUMMY_ACCOUNTS
[
0
].
address
,
DUMMY_ACCOUNTS
[
0
].
data
)
await
expect
(
OVM_StateManager
.
putAccount
(
DUMMY_ACCOUNTS
[
0
].
address
,
DUMMY_ACCOUNTS
[
1
].
data
)
).
to
.
not
.
be
.
reverted
})
})
describe
(
'
getAccount
'
,
()
=>
{
it
(
'
should be able to retrieve an OVM account
'
,
async
()
=>
{
await
OVM_StateManager
.
putAccount
(
DUMMY_ACCOUNTS
[
0
].
address
,
DUMMY_ACCOUNTS
[
0
].
data
)
expect
(
toOVMAccount
(
await
OVM_StateManager
.
callStatic
.
getAccount
(
DUMMY_ACCOUNTS
[
0
].
address
)
)
).
to
.
deep
.
equal
(
DUMMY_ACCOUNTS
[
0
].
data
)
})
it
(
'
should be able to retrieve an overwritten OVM account
'
,
async
()
=>
{
await
OVM_StateManager
.
putAccount
(
DUMMY_ACCOUNTS
[
0
].
address
,
DUMMY_ACCOUNTS
[
0
].
data
)
await
OVM_StateManager
.
putAccount
(
DUMMY_ACCOUNTS
[
0
].
address
,
DUMMY_ACCOUNTS
[
1
].
data
)
expect
(
toOVMAccount
(
await
OVM_StateManager
.
callStatic
.
getAccount
(
DUMMY_ACCOUNTS
[
0
].
address
)
)
).
to
.
deep
.
equal
(
DUMMY_ACCOUNTS
[
1
].
data
)
})
})
describe
(
'
hasAccount
'
,
()
=>
{
it
(
'
should return true if an account exists
'
,
async
()
=>
{
await
OVM_StateManager
.
putAccount
(
DUMMY_ACCOUNTS
[
0
].
address
,
DUMMY_ACCOUNTS
[
0
].
data
)
expect
(
await
OVM_StateManager
.
callStatic
.
hasAccount
(
DUMMY_ACCOUNTS
[
0
].
address
)
).
to
.
equal
(
true
)
})
it
(
'
should return false if the account does not exist
'
,
async
()
=>
{
expect
(
await
OVM_StateManager
.
callStatic
.
hasAccount
(
DUMMY_ACCOUNTS
[
0
].
address
)
).
to
.
equal
(
false
)
})
})
describe
(
'
putContractStorage
'
,
()
=>
{
it
(
'
should be able to insert a storage slot for a given contract
'
,
async
()
=>
{
await
expect
(
OVM_StateManager
.
putContractStorage
(
DUMMY_ACCOUNTS
[
0
].
address
,
DUMMY_BYTES32
[
0
],
DUMMY_BYTES32
[
1
],
)
).
to
.
not
.
be
.
reverted
})
it
(
'
should be able to overwrite a storage slot for a given contract
'
,
async
()
=>
{
await
OVM_StateManager
.
putContractStorage
(
DUMMY_ACCOUNTS
[
0
].
address
,
DUMMY_BYTES32
[
0
],
DUMMY_BYTES32
[
1
],
)
await
expect
(
OVM_StateManager
.
putContractStorage
(
DUMMY_ACCOUNTS
[
0
].
address
,
DUMMY_BYTES32
[
0
],
DUMMY_BYTES32
[
2
],
)
).
to
.
not
.
be
.
reverted
})
})
describe
(
'
getContractStorage
'
,
()
=>
{
it
(
'
should be able to retrieve a storage slot for a given contract
'
,
async
()
=>
{
await
OVM_StateManager
.
putContractStorage
(
DUMMY_ACCOUNTS
[
0
].
address
,
DUMMY_BYTES32
[
0
],
DUMMY_BYTES32
[
1
],
)
expect
(
await
OVM_StateManager
.
callStatic
.
getContractStorage
(
DUMMY_ACCOUNTS
[
0
].
address
,
DUMMY_BYTES32
[
0
]
)
).
to
.
equal
(
DUMMY_BYTES32
[
1
])
})
it
(
'
should be able to retrieve an overwritten storage slot for a given contract
'
,
async
()
=>
{
await
OVM_StateManager
.
putContractStorage
(
DUMMY_ACCOUNTS
[
0
].
address
,
DUMMY_BYTES32
[
0
],
DUMMY_BYTES32
[
1
],
)
await
OVM_StateManager
.
putContractStorage
(
DUMMY_ACCOUNTS
[
0
].
address
,
DUMMY_BYTES32
[
0
],
DUMMY_BYTES32
[
2
],
)
expect
(
await
OVM_StateManager
.
callStatic
.
getContractStorage
(
DUMMY_ACCOUNTS
[
0
].
address
,
DUMMY_BYTES32
[
0
]
)
).
to
.
equal
(
DUMMY_BYTES32
[
2
])
})
})
})
packages/contracts/test/contracts/proxy/Proxy_Forwarder.spec.ts
0 → 100644
View file @
954e87cd
import
{
expect
}
from
'
../../setup
'
/* External Imports */
import
{
ethers
}
from
'
@nomiclabs/buidler
'
import
{
Contract
,
ContractFactory
}
from
'
ethers
'
describe
(
'
Proxy_Forwarder
'
,
()
=>
{
describe
(
'
fallback
'
,
()
=>
{
})
})
packages/contracts/test/contracts/proxy/Proxy_Manager.spec.ts
0 → 100644
View file @
954e87cd
import
{
expect
}
from
'
../../setup
'
/* External Imports */
import
{
ethers
}
from
'
@nomiclabs/buidler
'
import
{
Contract
,
ContractFactory
}
from
'
ethers
'
describe
(
'
Proxy_Manager
'
,
()
=>
{
describe
(
'
setProxy
'
,
()
=>
{
})
describe
(
'
getProxy
'
,
()
=>
{
})
describe
(
'
hasProxy
'
,
()
=>
{
})
describe
(
'
isProxy
'
,
()
=>
{
})
describe
(
'
setTarget
'
,
()
=>
{
})
describe
(
'
getTarget
'
,
()
=>
{
})
describe
(
'
hasTarget
'
,
()
=>
{
})
describe
(
'
isTarget
'
,
()
=>
{
})
})
packages/contracts/test/contracts/proxy/Proxy_Resolver.spec.ts
0 → 100644
View file @
954e87cd
import
{
expect
}
from
'
../../setup
'
/* External Imports */
import
{
ethers
}
from
'
@nomiclabs/buidler
'
import
{
Contract
,
ContractFactory
}
from
'
ethers
'
describe
(
'
Proxy_Resolver
'
,
()
=>
{
describe
(
'
resolve
'
,
()
=>
{
})
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment