Skip to content

Commit

Permalink
Switch to storage manager
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronbuchwald committed Oct 16, 2021
1 parent 5df0cb2 commit 40acb44
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 58 deletions.
55 changes: 0 additions & 55 deletions core/Owner.sol

This file was deleted.

51 changes: 51 additions & 0 deletions core/Storage.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// SPDX-License-Identifier: GPL-3.0

pragma solidity >=0.7.0 <=0.8.9;

/**
* @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;
}

/**
* @dev Return value
* @return value of 'number'
*/
function retrieve() public view returns (uint256){
return number;
}
}

contract StorageManager {
// track storage contracts we've created

address[] public storageAddrs;

function create() public {
Storage strContract = new Storage();
storageAddrs.push(address(strContract));
}

function store(uint256 index, uint256 num) public {
require(index < storageAddrs.length, "invalid index");
Storage strContract = Storage(storageAddrs[index]);
strContract.store(num);
}

function retrieve(uint256 index) public view returns (uint256) {
require(index < storageAddrs.length, "invalid index");
Storage strContract = Storage(storageAddrs[index]);
return strContract.retrieve();
}
}
6 changes: 3 additions & 3 deletions core/bench_concurrent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func benchmarkArbitraryBlockExecution(b *testing.B, numBlocks int, numTxs int, r
genesis := gspec.MustCommit(db)

gopath := os.Getenv("GOPATH")
contractSrc, err := filepath.Abs(gopath + "/src/github.com/ethereum/go-ethereum/core/Owner.sol")
contractSrc, err := filepath.Abs(gopath + "/src/github.com/ethereum/go-ethereum/core/Storage.sol")
if err != nil {
b.Fatal(err)
}
Expand All @@ -71,9 +71,9 @@ func benchmarkArbitraryBlockExecution(b *testing.B, numBlocks int, numTxs int, r
}
numContracts := 10
contractAddrs := make([]common.Address, 0, numContracts)
contract, exists := contracts[fmt.Sprintf("%s:%s", contractSrc, "Owner")]
contract, exists := contracts[fmt.Sprintf("%s:%s", contractSrc, "Storage")]
if !exists {
contract, exists = contracts["Owner.sol:Owner"]
contract, exists = contracts["Storage.sol:Storage"]
}
if !exists {
b.Fatal("contract doesn't exist")
Expand Down

0 comments on commit 40acb44

Please sign in to comment.