Skip to content

Commit

Permalink
testcases added for structs
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Furter committed Jul 31, 2018
1 parent aa36e09 commit 64929a2
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 3 deletions.
4 changes: 2 additions & 2 deletions dist/web3.js
Original file line number Diff line number Diff line change
Expand Up @@ -24488,8 +24488,8 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
if (!this.provider) {
return callback(errors.InvalidProvider());
}

var payload = Jsonrpc.toPayload(data.method, data.params);
console.log('payload', payload);
this.provider[this.provider.sendAsync ? 'sendAsync' : 'send'](payload, function (err, result) {
if (result && result.id && payload.id !== result.id) return callback(new Error('Wrong response id "' + result.id + '" (expected: "' + payload.id + '") in ' + JSON.stringify(payload)));

Expand All @@ -24504,7 +24504,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
if (!Jsonrpc.isValidResponse(result)) {
return callback(errors.InvalidResponse(result));
}

console.log('result', result);
callback(null, result.result);
});
};
Expand Down
2 changes: 1 addition & 1 deletion dist/web3.min.js

Large diffs are not rendered by default.

90 changes: 90 additions & 0 deletions test/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,43 @@ var abi = [{
"name": "myValue",
"type": "uint256"
}]
},{
"constant": false,
"inputs": [
{
"components": [
{"name": "status", "type": "bool"}
],
"name": "nestedStruct",
"type": "tuple"
}
],
"name": "addStruct",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},{
"constant": true,
"inputs": [
{
"name": "",
"type": "address"
}
],
"name": "listOfNestedStructs",
"outputs": [
{
"components": [
{"name": "status", "type": "bool"}
],
"name": "nestedStruct",
"type": "tuple"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},{
"name": "balance",
"type": "function",
Expand Down Expand Up @@ -2787,6 +2824,59 @@ var runTests = function(contractFactory) {
});

});


it('should decode an struct correctly', function (done) {
var provider = new FakeIpcProvider();

provider.injectValidation(function (payload) {
assert.equal(payload.method, 'eth_call');
assert.deepEqual(payload.params, [{
data: '0x2a4aedd50000000000000000000000009cc9a2c777605af16872e0997b3aeb91d96d5d8c',
to: addressLowercase
},
'latest'
]);
});

provider.injectResult('0x0000000000000000000000000000000000000000000000000000000000000001');

var contract = contractFactory(abi, address, provider);

contract.methods.listOfNestedStructs('0x9CC9a2c777605Af16872E0997b3Aeb91d96D5D8c').call().then(function(result) {
var expectedArray = [];
expectedArray[0] = true;
expectedArray['status'] = true;

assert.deepEqual(result, expectedArray);
done();
});
});

it('should call an contract method with an struct as parameter', function (done) {
var provider = new FakeIpcProvider();

provider.injectValidation(function (payload) {
assert.equal(payload.method, 'eth_sendTransaction');
assert.deepEqual(payload.params, [{
data: '0x814a4d160000000000000000000000000000000000000000000000000000000000000001',
from: addressLowercase,
gas: '0xc350',
gasPrice: '0xbb8',
to: addressLowercase
}]);

done();
});

var contract = contractFactory(abi, address, provider);

contract.methods.addStruct({status: true}).send({
from: address,
gas: 50000,
gasPrice: 3000
});
});
});
describe('with data', function () {
it('should deploy a contract and use callback', function (done) {
Expand Down

0 comments on commit 64929a2

Please sign in to comment.