Skip to content

Commit 5257574

Browse files
committed
UnitTest.hs: ensure caller is set correctly in test
1 parent 574ef40 commit 5257574

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/hevm/src/EVM/UnitTest.hs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ initializeUnitTest UnitTestOptions { .. } = do
124124
-- Initialize the test contract
125125
Stepper.evm (popTrace >> pushTrace (EntryTrace "initialize test"))
126126
Stepper.evm $
127-
setupCall addr "setUp()" (testGasCall testParams)
127+
setupCall testParams addr "setUp()"
128128

129129
Stepper.note "Running `setUp()'"
130130

@@ -152,7 +152,7 @@ runUnitTest UnitTestOptions { .. } method = do
152152

153153
-- Set up the call to the test method
154154
Stepper.evm $
155-
setupCall addr method (testGasCall testParams)
155+
setupCall testParams addr method
156156
Stepper.evm (pushTrace (EntryTrace method))
157157
Stepper.note "Running unit test"
158158

@@ -171,7 +171,7 @@ runUnitTest UnitTestOptions { .. } method = do
171171

172172
-- Ask whether any assertions failed
173173
Stepper.evm $ popTrace
174-
Stepper.evm $ setupCall addr "failed()" 10000
174+
Stepper.evm $ setupCall testParams addr "failed()"
175175
Stepper.note "Checking whether assertions failed"
176176
res <- Stepper.execFullyOrFail >>= Stepper.decode AbiBoolType
177177
let AbiBool failed = res
@@ -528,12 +528,14 @@ formatTestLog events (Log _ args (topic:_)) =
528528
word32Bytes :: Word32 -> ByteString
529529
word32Bytes x = BS.pack [byteAt x (3 - i) | i <- [0..3]]
530530

531-
setupCall :: Addr -> Text -> W256 -> EVM ()
532-
setupCall target abi allowance = do
531+
setupCall :: TestVMParams -> Addr -> Text -> EVM ()
532+
setupCall params target abi = do
533+
let TestVMParams {..} = params
533534
resetState
534535
loadContract target
535536
assign (state . calldata) (word32Bytes (abiKeccak (encodeUtf8 abi)))
536-
assign (state . gas) (w256 allowance)
537+
assign (state . caller) testCaller
538+
assign (state . gas) (w256 testGasCall)
537539

538540
initialUnitTestVm :: UnitTestOptions -> SolcContract -> [SolcContract] -> VM
539541
initialUnitTestVm (UnitTestOptions {..}) theContract _ =

0 commit comments

Comments
 (0)