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
cde4e59f
Unverified
Commit
cde4e59f
authored
Apr 12, 2021
by
smartcontracts
Committed by
GitHub
Apr 12, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[smock] dev: Use latest smock codebase (#429)
* dev: Use latest smock codebase * Update package.json
parent
3bfb2d65
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
1 addition
and
102 deletions
+1
-102
package.json
packages/smock/package.json
+1
-1
binding.ts
packages/smock/src/smoddit/binding.ts
+0
-101
No files found.
packages/smock/package.json
View file @
cde4e59f
{
{
"name"
:
"@eth-optimism/smock"
,
"name"
:
"@eth-optimism/smock"
,
"version"
:
"1.0.0-alpha.
3
"
,
"version"
:
"1.0.0-alpha.
7
"
,
"main"
:
"dist/src/index"
,
"main"
:
"dist/src/index"
,
"types"
:
"dist/src/index"
,
"types"
:
"dist/src/index"
,
"files"
:
[
"files"
:
[
...
...
packages/smock/src/smoddit/binding.ts
deleted
100644 → 0
View file @
3bfb2d65
/* External Imports */
import
{
toHexString
,
fromHexString
}
from
'
@eth-optimism/core-utils
'
import
{
HardhatNetworkProvider
}
from
'
hardhat/internal/hardhat-network/provider/provider
'
/* Internal Imports */
import
{
ModifiableContract
}
from
'
./types
'
/**
* Checks to see if smoddit has been initialized already.
* @param provider Base hardhat network provider to check.
* @return Whether or not the provider has already been modified to support smoddit.
*/
const
isSmodInitialized
=
(
provider
:
HardhatNetworkProvider
):
boolean
=>
{
return
(
provider
as
any
).
_node
.
_vm
.
_smod
!==
undefined
}
/**
* Initializes smodding functionality.
* @param provider Base hardhat network provider to modify.
*/
const
initializeSmod
=
(
provider
:
HardhatNetworkProvider
):
void
=>
{
if
(
isSmodInitialized
(
provider
))
{
return
}
// Will need to reference these things.
const
node
=
(
provider
as
any
).
_node
const
vm
=
node
.
_vm
const
pStateManager
=
vm
.
pStateManager
vm
.
_smod
=
{
contracts
:
{},
}
const
originalGetStorageFn
=
pStateManager
.
getContractStorage
.
bind
(
pStateManager
)
pStateManager
.
getContractStorage
=
async
(
addressBuf
:
Buffer
,
keyBuf
:
Buffer
):
Promise
<
Buffer
>
=>
{
const
originalReturnValue
=
await
originalGetStorageFn
(
addressBuf
,
keyBuf
)
const
address
=
toHexString
(
addressBuf
).
toLowerCase
()
const
key
=
toHexString
(
keyBuf
).
toLowerCase
()
if
(
!
(
address
in
vm
.
_smod
.
contracts
))
{
return
originalReturnValue
}
const
contract
:
ModifiableContract
=
vm
.
_smod
.
contracts
[
address
]
if
(
!
(
key
in
contract
.
_smodded
))
{
return
originalReturnValue
}
return
fromHexString
(
contract
.
_smodded
[
key
])
}
const
originalPutStorageFn
=
pStateManager
.
putContractStorage
.
bind
(
pStateManager
)
pStateManager
.
putContractStorage
=
async
(
addressBuf
:
Buffer
,
keyBuf
:
Buffer
,
valBuf
:
Buffer
):
Promise
<
void
>
=>
{
await
originalPutStorageFn
(
addressBuf
,
keyBuf
,
valBuf
)
const
address
=
toHexString
(
addressBuf
).
toLowerCase
()
const
key
=
toHexString
(
keyBuf
).
toLowerCase
()
if
(
!
(
address
in
vm
.
_smod
.
contracts
))
{
return
}
const
contract
:
ModifiableContract
=
vm
.
_smod
.
contracts
[
address
]
if
(
!
(
key
in
contract
.
_smodded
))
{
return
}
delete
contract
.
_smodded
[
key
]
}
}
/**
* Binds the smodded contract to the VM.
* @param contract Contract to bind.
*/
export
const
bindSmod
=
(
contract
:
ModifiableContract
,
provider
:
HardhatNetworkProvider
):
void
=>
{
if
(
!
isSmodInitialized
(
provider
))
{
initializeSmod
(
provider
)
}
const
vm
=
(
provider
as
any
).
_node
.
_vm
// Add mock to our list of mocks currently attached to the VM.
vm
.
_smod
.
contracts
[
contract
.
address
.
toLowerCase
()]
=
contract
}
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