I'm pretty new to Solidity, and I was writing a contract to play around with dynamic arrays. My array length grows, but it seems to stop at length 8.
Here's the contract I wrote:
pragma solidity 0.4.19;
contract BigData {
bytes public doubleBag = "1";
function doubleStorage() public {
uint256 index = 0;
uint256 addThisMany = doubleBag.length;
while (index < addThisMany) {
doubleBag.push("1");
index += 1;
}
}
function getLength() public view returns (uint256) {
return doubleBag.length;
}
}
And the truffle test with web3@^0.20.6:
var BigData = artifacts.require('./BigData.sol')
const BigNumber = require('bignumber.js')
contract('BigData', function(accounts) {
it('Should grow storage exponentially', async function() {
let contract = await BigData.deployed()
for (let i = 1; i <= 3; i++) {
let tx = await contract.doubleStorage()
let size = await contract.getLength()
let expected = i * 2
assert.equal(size.toNumber(), expected)
}
})
})
doubleStorage? – user19510 Mar 15 '18 at 21:26