I see strange behavior when I try to execute some test contracts. I have made 2 test contracts,
contract TestContract1 {
uint public n;
uint public testValue1;
bytes6 public value;
function TestContract1(bytes6 val, uint[] testArray) {
n = testArray.length;
testValue1 = testArray[0];
value = val;
}
}
and
contract TestContract4 {
uint public n;
uint public testValue1;
uint public value;
function TestContract4(uint val, uint[] testArray) {
n = testArray.length;
testValue1 = testArray[0];
value = val;
}
}
These contracts are identical, except for the val, parameter, which is a uint in TestContract4 and bytes6 in TestContract1.
I execute contract #4 by the following code from geth:
var testContract = web3.eth.contract(abiArray);
var test = testContract.new(
0x313131314141, [123,456],
{
data:contractCode,
from: eth.accounts[0],
gas: 1000000
}, function(e, contract){
console.log(e, contract);
if (typeof contract.address != 'undefined') {
console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
}
});
and I look at the different variables stored in the contract, all values are correctly stored and retrieved (i.e. n = 2, testValue1 = 123, value = 54087348470081).
When I execute contract #1 with the same code from geth, I get a correct value = 0x313131314141, but n and testValue1 have strange values (n = 10696049115004928, testValue1 = 562949953421312).
Further tests show that when I change the bytes6
to bytes32
the contract works ok. Other lengths other than 32 seem to have the erroneous behavior.
It looks like a bug in Geth, since testing the contract in Solidity browser seems to work correctly.