Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Commit

Permalink
Unit test for calling SSTORE with gas below stipend
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Sep 3, 2019
1 parent d00a436 commit f81ea73
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/unittests/libevm/VMTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,29 @@ class SstoreTestFixture : public TestOutputHelperFixture

void testIstanbul() { testAllCases(istanbulCases, Network::IstanbulTest); }

void sstoreBelowStipend(Network _network)
{
// sstore(0, 0)
bytes const code = fromHex("6000600055");

std::unique_ptr<SealEngineFace> se{ChainParams(genesisInfo(_network)).createSealEngine()};
EnvInfo envInfo{blockHeader, lastBlockHashes, 0, se->chainParams().chainID};
ExtVM extVm(state, envInfo, *se, to, from, from, value, gasPrice, inputData, ref(code),
sha3(code), version, depth, isCreate, staticCall);

u256 gas = 2300;
vm->exec(gas, extVm, OnOpFunc{});
}

void testSstoreBelowStipend()
{
sstoreBelowStipend(Network::ConstantinopleTest); // shouldn't throw

BOOST_CHECK_THROW(sstoreBelowStipend(Network::ConstantinopleFixTest), OutOfGas);

BOOST_CHECK_THROW(sstoreBelowStipend(Network::IstanbulTest), OutOfGas);
}

BlockHeader blockHeader{initBlockHeader()};
LastBlockHashes lastBlockHashes;
Address from{KeyPair::create().address()};
Expand Down Expand Up @@ -849,6 +872,11 @@ BOOST_AUTO_TEST_CASE(LegacyVMSstoreIstanbul)
testIstanbul();
}

BOOST_AUTO_TEST_CASE(LegacyVMSstoreBelowStipend)
{
testSstoreBelowStipend();
}

BOOST_AUTO_TEST_SUITE_END()
BOOST_FIXTURE_TEST_SUITE(LegacyVMChainIDSuite, LegacyVMChainIDTestFixture)

Expand Down

0 comments on commit f81ea73

Please sign in to comment.