forked from cerc-io/laconicd-deprecated
evm: use clean context for GetCommittedState (#383)
* keep the original context for GetCommittedState api * fix method mutation * keep estimateGas consistant * added test after the original context is recovered * add integration test for the gas consumption of sstore * test the committed case * move methods to keeper module Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
This commit is contained in:
co-authored by
Federico Kunze Küllmer
parent
f7bcc8d12e
commit
9bf3659718
@@ -0,0 +1,29 @@
|
||||
// SPDX-License-Identifier: GPL-3.0
|
||||
|
||||
pragma solidity ^0.5.11;
|
||||
|
||||
/**
|
||||
* @title Storage
|
||||
* @dev Store & retrieve value in a variable
|
||||
*/
|
||||
contract Storage {
|
||||
|
||||
uint256 number;
|
||||
|
||||
/**
|
||||
* @dev Store value in variable
|
||||
* @param num value to store
|
||||
*/
|
||||
function store(uint256 num) public {
|
||||
number = num + 1;
|
||||
number = num;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Return value
|
||||
* @return value of 'number'
|
||||
*/
|
||||
function retrieve() public view returns (uint256){
|
||||
return number;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
const Storage = artifacts.require("Storage")
|
||||
|
||||
contract('Storage', (accounts) => {
|
||||
|
||||
let storage
|
||||
beforeEach(async () => {
|
||||
storage = await Storage.new()
|
||||
})
|
||||
|
||||
it('estimated gas should match', async () => {
|
||||
// set new value
|
||||
let gasUsage = await storage.store.estimateGas(10);
|
||||
expect(gasUsage.toString()).to.equal('43754');
|
||||
|
||||
await storage.store(10);
|
||||
|
||||
// set existing value
|
||||
gasUsage = await storage.store.estimateGas(10);
|
||||
expect(gasUsage.toString()).to.equal('28754');
|
||||
})
|
||||
|
||||
})
|
||||
Reference in New Issue
Block a user