Skip to content

Commit

Permalink
Adding changes related to value parameter for payable function in Eth…
Browse files Browse the repository at this point in the history
…ereum. (#1122)

* Adding changes related to value parameter.

Signed-off-by: Nachiket Tapas <[email protected]>

* Changes to the simple contract

Signed-off-by: Nachiket Tapas <[email protected]>
  • Loading branch information
nachikettapas authored Jan 21, 2021
1 parent 69eec09 commit 12a3e52
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 70 deletions.
3 changes: 3 additions & 0 deletions packages/caliper-ethereum/lib/ethereum-connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ class EthereumConnector extends ConnectorBase {
const context = this.context;
let status = new TxStatus();
let params = {from: context.fromAddress};
if (request.hasOwnProperty('value') && request.value > 0) {
params.value = request.value;
}
let contractInfo = context.contracts[request.contract];

let receipt = null;
Expand Down
1 change: 1 addition & 0 deletions packages/caliper-tests-integration/ethereum_tests/open.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class SimpleOpenWorkload extends WorkloadModuleBase {
workload.push({
contract: 'simple',
verb: 'open',
value: this.roundArguments.money,
args: [accountId, this.roundArguments.money],
readOnly: false
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,73 +1,73 @@
{
"name": "simple",
"abi": [
{
"constant": false,
"inputs": [
{
"internalType": "string",
"name": "acc_from",
"type": "string"
},
{
"internalType": "string",
"name": "acc_to",
"type": "string"
},
{
"internalType": "int256",
"name": "amount",
"type": "int256"
}
],
"name": "transfer",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"internalType": "string",
"name": "acc_id",
"type": "string"
}
],
"name": "query",
"outputs": [
{
"internalType": "int256",
"name": "amount",
"type": "int256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "string",
"name": "acc_id",
"type": "string"
},
{
"internalType": "int256",
"name": "amount",
"type": "int256"
}
],
"name": "open",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}
{
"constant": false,
"inputs": [
{
"internalType": "string",
"name": "acc_id",
"type": "string"
},
{
"internalType": "int256",
"name": "amount",
"type": "int256"
}
],
"name": "open",
"outputs": [],
"payable": true,
"stateMutability": "payable",
"type": "function"
},
{
"constant": true,
"inputs": [
{
"internalType": "string",
"name": "acc_id",
"type": "string"
}
],
"name": "query",
"outputs": [
{
"internalType": "int256",
"name": "amount",
"type": "int256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "string",
"name": "acc_from",
"type": "string"
},
{
"internalType": "string",
"name": "acc_to",
"type": "string"
},
{
"internalType": "int256",
"name": "amount",
"type": "int256"
}
],
"name": "transfer",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}
],
"bytecode": "0x608060405234801561001057600080fd5b50610542806100206000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c80631de45b10146100465780637c261929146101a25780639064129314610271575b600080fd5b6101a06004803603606081101561005c57600080fd5b810190808035906020019064010000000081111561007957600080fd5b82018360208201111561008b57600080fd5b803590602001918460018302840111640100000000831117156100ad57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192908035906020019064010000000081111561011057600080fd5b82018360208201111561012257600080fd5b8035906020019184600183028401116401000000008311171561014457600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050919291929080359060200190929190505050610336565b005b61025b600480360360208110156101b857600080fd5b81019080803590602001906401000000008111156101d557600080fd5b8201836020820111156101e757600080fd5b8035906020019184600183028401116401000000008311171561020957600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050610429565b6040518082815260200191505060405180910390f35b6103346004803603604081101561028757600080fd5b81019080803590602001906401000000008111156102a457600080fd5b8201836020820111156102b657600080fd5b803590602001918460018302840111640100000000831117156102d857600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192908035906020019092919050505061049b565b005b806000846040518082805190602001908083835b6020831061036d578051825260208201915060208101905060208303925061034a565b6001836020036101000a038019825116818451168082178552505050505050905001915050908152602001604051809103902060008282540392505081905550806000836040518082805190602001908083835b602083106103e457805182526020820191506020810190506020830392506103c1565b6001836020036101000a038019825116818451168082178552505050505050905001915050908152602001604051809103902060008282540192505081905550505050565b600080826040518082805190602001908083835b60208310610460578051825260208201915060208101905060208303925061043d565b6001836020036101000a0380198251168184511680821785525050505050509050019150509081526020016040518091039020549050919050565b806000836040518082805190602001908083835b602083106104d257805182526020820191506020810190506020830392506104af565b6001836020036101000a038019825116818451168082178552505050505050905001915050908152602001604051809103902081905550505056fea265627a7a72315820f89fa48c6c4d5d7df165b5e3dba04cbe258ce57a3a4ef3bab1377546b84b699f64736f6c634300050b0032",
"bytecode": "0x608060405234801561001057600080fd5b506105c8806100206000396000f3fe6080604052600436106100345760003560e01c80631de45b10146100395780637c261929146101a2578063906412931461027e575b600080fd5b34801561004557600080fd5b506101a06004803603606081101561005c57600080fd5b810190808035906020019064010000000081111561007957600080fd5b82018360208201111561008b57600080fd5b803590602001918460018302840111640100000000831117156100ad57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192908035906020019064010000000081111561011057600080fd5b82018360208201111561012257600080fd5b8035906020019184600183028401116401000000008311171561014457600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050919291929080359060200190929190505050610343565b005b3480156101ae57600080fd5b50610268600480360360208110156101c557600080fd5b81019080803590602001906401000000008111156101e257600080fd5b8201836020820111156101f457600080fd5b8035906020019184600183028401116401000000008311171561021657600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050610436565b6040518082815260200191505060405180910390f35b6103416004803603604081101561029457600080fd5b81019080803590602001906401000000008111156102b157600080fd5b8201836020820111156102c357600080fd5b803590602001918460018302840111640100000000831117156102e557600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290803590602001909291905050506104a8565b005b806000846040518082805190602001908083835b6020831061037a5780518252602082019150602081019050602083039250610357565b6001836020036101000a038019825116818451168082178552505050505050905001915050908152602001604051809103902060008282540392505081905550806000836040518082805190602001908083835b602083106103f157805182526020820191506020810190506020830392506103ce565b6001836020036101000a038019825116818451168082178552505050505050905001915050908152602001604051809103902060008282540192505081905550505050565b600080826040518082805190602001908083835b6020831061046d578051825260208201915060208101905060208303925061044a565b6001836020036101000a0380198251168184511680821785525050505050509050019150509081526020016040518091039020549050919050565b803414610500576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260218152602001806105736021913960400191505060405180910390fd5b806000836040518082805190602001908083835b602083106105375780518252602082019150602081019050602083039250610514565b6001836020036101000a038019825116818451168082178552505050505050905001915050908152602001604051809103902081905550505056fe4e6f20636f6d6d69746d656e74206d616465206279207468652063616c6c65722ea265627a7a72315820f76b07509e537883b5471090aeca0a231503064fc2dc6bfbd81169217bd96c2464736f6c63430005110032",
"gas": 4700000
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ pragma solidity >=0.4.22 <0.6.0;
contract simple {
mapping(string => int) private accounts;

function open(string memory acc_id, int amount) public {
function open(string memory acc_id, int amount) public payable {
require(int(msg.value) == amount, 'No commitment made by the caller.');
accounts[acc_id] = amount;
}

Expand All @@ -15,4 +16,4 @@ contract simple {
accounts[acc_from] -= amount;
accounts[acc_to] += amount;
}
}
}

0 comments on commit 12a3e52

Please sign in to comment.