Skip to content

Commit

Permalink
Add string event integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cgewecke committed May 4, 2020
1 parent 3e10668 commit 43ef593
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 20 deletions.
46 changes: 46 additions & 0 deletions test/e2e.contract.events.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,5 +279,51 @@ describe('contract.events [ @E2E ]', function() {
assert.equal(childEvents[1].event, 'Identical');
assert.equal(typeof childEvents[1].returnValues.childA, 'string');
});

it('when event param is a simple string', async function(){
const msg = 'simplestring';

await instance
.methods
.firesStringEvent(msg)
.send({from: accounts[0]});

const events = await instance.getPastEvents({
fromBlock: 0,
toBlock: 'latest'
});

assert.equal(events[0].returnValues.str, msg)
});

it('when an invalid utf-8 string is passed in JS as param to emit', async function(){
const msg = '�������';

await instance
.methods
.firesStringEvent(msg)
.send({from: accounts[0]});

const events = await instance.getPastEvents({
fromBlock: 0,
toBlock: 'latest'
});

assert.equal(msg, events[0].returnValues.str)
});

it('when Solidity emits an invalid utf-8 string', async function(){
await instance
.methods
.firesIllegalUtf8StringEvent()
.send({from: accounts[0]});

const events = await instance.getPastEvents({
fromBlock: 0,
toBlock: 'latest'
});

assert.equal('�������', events[0].returnValues.str)
});
});

105 changes: 85 additions & 20 deletions test/sources/Basic.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,44 +21,105 @@
"type": "event"
},
{
"constant": true,
"inputs": [],
"name": "getValue",
"outputs": [
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "string",
"name": "str",
"type": "string"
}
],
"name": "IndexedStringEvent",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "string",
"name": "str",
"type": "string"
}
],
"name": "StringEvent",
"type": "event"
},
{
"constant": false,
"inputs": [
{
"internalType": "address",
"name": "addr",
"type": "address"
},
{
"internalType": "uint256",
"name": "val",
"type": "uint256"
}
],
"name": "firesEvent",
"outputs": [],
"payable": false,
"stateMutability": "view",
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "firesIllegalUtf8StringEvent",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{
"internalType": "uint256",
"name": "_value",
"type": "uint256"
"internalType": "string",
"name": "_str",
"type": "string"
}
],
"name": "setValue",
"name": "firesIndexedStringEvent",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "requireWithoutReason",
"inputs": [
{
"internalType": "string",
"name": "_str",
"type": "string"
}
],
"name": "firesStringEvent",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "getValue",
"outputs": [
{
"internalType": "uint256",
"name": "val",
"type": "uint256"
}
],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [],
Expand All @@ -68,6 +129,15 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "requireWithoutReason",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [],
Expand All @@ -80,26 +150,21 @@
{
"constant": false,
"inputs": [
{
"internalType": "address",
"name": "addr",
"type": "address"
},
{
"internalType": "uint256",
"name": "val",
"name": "_value",
"type": "uint256"
}
],
"name": "firesEvent",
"name": "setValue",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}
],
"bytecode": "0x608060405234801561001057600080fd5b506102c0806100206000396000f3fe608060405234801561001057600080fd5b50600436106100625760003560e01c806320965255146100675780633bccbbc914610085578063552410771461008f578063844d6a32146100bd57806385693803146100c7578063ae012ede14610115575b600080fd5b61006f61011f565b6040518082815260200191505060405180910390f35b61008d610128565b005b6100bb600480360360208110156100a557600080fd5b8101908080359060200190929190505050610196565b005b6100c56101a0565b005b610113600480360360408110156100dd57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610216565b005b61011d61027e565b005b60008054905090565b6040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260148152602001807f524556455254454420574954482052455645525400000000000000000000000081525060200191505060405180910390fd5b8060008190555050565b6000610214576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260158152602001807f524556455254454420574954482052455155495245000000000000000000000081525060200191505060405180910390fd5b565b807f929af6b98ce8455e51b1e90cceeeec03ce38d7c7396f1f0b0233d043c898a29c83604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a25050565b600061028957600080fd5b56fea265627a7a72315820884747d21b82b34af8a11b3a5556963c8f2c8cf51df66f4c73e3ea5d33b1d44964736f6c634300050c0032",
"deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100625760003560e01c806320965255146100675780633bccbbc914610085578063552410771461008f578063844d6a32146100bd57806385693803146100c7578063ae012ede14610115575b600080fd5b61006f61011f565b6040518082815260200191505060405180910390f35b61008d610128565b005b6100bb600480360360208110156100a557600080fd5b8101908080359060200190929190505050610196565b005b6100c56101a0565b005b610113600480360360408110156100dd57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff16906020019092919080359060200190929190505050610216565b005b61011d61027e565b005b60008054905090565b6040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260148152602001807f524556455254454420574954482052455645525400000000000000000000000081525060200191505060405180910390fd5b8060008190555050565b6000610214576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260158152602001807f524556455254454420574954482052455155495245000000000000000000000081525060200191505060405180910390fd5b565b807f929af6b98ce8455e51b1e90cceeeec03ce38d7c7396f1f0b0233d043c898a29c83604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a25050565b600061028957600080fd5b56fea265627a7a72315820884747d21b82b34af8a11b3a5556963c8f2c8cf51df66f4c73e3ea5d33b1d44964736f6c634300050c0032",
"bytecode": "0x608060405234801561001057600080fd5b50610619806100206000396000f3fe608060405234801561001057600080fd5b50600436106100935760003560e01c806360fea5e41161006657806360fea5e4146100f8578063844d6a32146101b357806385693803146101bd578063ae012ede1461020b578063b7a8238a1461021557610093565b806320965255146100985780633aebabe6146100b65780633bccbbc9146100c057806355241077146100ca575b600080fd5b6100a06102d0565b6040518082815260200191505060405180910390f35b6100be6102d9565b005b6100c8610343565b005b6100f6600480360360208110156100e057600080fd5b81019080803590602001909291905050506103b1565b005b6101b16004803603602081101561010e57600080fd5b810190808035906020019064010000000081111561012b57600080fd5b82018360208201111561013d57600080fd5b8035906020019184600183028401116401000000008311171561015f57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192905050506103bb565b005b6101bb61045a565b005b610209600480360360408110156101d357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506104d0565b005b610213610538565b005b6102ce6004803603602081101561022b57600080fd5b810190808035906020019064010000000081111561024857600080fd5b82018360208201111561025a57600080fd5b8035906020019184600183028401116401000000008311171561027c57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050610545565b005b60008054905090565b7f617cf8a4400dd7963ed519ebe655a16e8da1282bb8fea36a21f634af912f54ab6040518080602001828103825260158152602001807fefbfbdefbfbdefbfbdefbfbdefbfbdefbfbdefbfbd000000000000000000000081525060200191505060405180910390a1565b6040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260148152602001807f524556455254454420574954482052455645525400000000000000000000000081525060200191505060405180910390fd5b8060008190555050565b7f82dd7094dfd71d508c7a8ff013f3064664025068543bf228f7194a862cdfe3d7816040518080602001828103825283818151815260200191508051906020019080838360005b8381101561041d578082015181840152602081019050610402565b50505050905090810190601f16801561044a5780820380516001836020036101000a031916815260200191505b509250505060405180910390a150565b60006104ce576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260158152602001807f524556455254454420574954482052455155495245000000000000000000000081525060200191505060405180910390fd5b565b807f929af6b98ce8455e51b1e90cceeeec03ce38d7c7396f1f0b0233d043c898a29c83604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a25050565b600061054357600080fd5b565b7f617cf8a4400dd7963ed519ebe655a16e8da1282bb8fea36a21f634af912f54ab816040518080602001828103825283818151815260200191508051906020019080838360005b838110156105a757808201518184015260208101905061058c565b50505050905090810190601f1680156105d45780820380516001836020036101000a031916815260200191505b509250505060405180910390a15056fea265627a7a7231582069bac219e1bd2bb93a98f42a0d7aa83ba402f2168ab48df5ba385e348b9b3e8864736f6c634300050f0032",
"deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100935760003560e01c806360fea5e41161006657806360fea5e4146100f8578063844d6a32146101b357806385693803146101bd578063ae012ede1461020b578063b7a8238a1461021557610093565b806320965255146100985780633aebabe6146100b65780633bccbbc9146100c057806355241077146100ca575b600080fd5b6100a06102d0565b6040518082815260200191505060405180910390f35b6100be6102d9565b005b6100c8610343565b005b6100f6600480360360208110156100e057600080fd5b81019080803590602001909291905050506103b1565b005b6101b16004803603602081101561010e57600080fd5b810190808035906020019064010000000081111561012b57600080fd5b82018360208201111561013d57600080fd5b8035906020019184600183028401116401000000008311171561015f57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192905050506103bb565b005b6101bb61045a565b005b610209600480360360408110156101d357600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506104d0565b005b610213610538565b005b6102ce6004803603602081101561022b57600080fd5b810190808035906020019064010000000081111561024857600080fd5b82018360208201111561025a57600080fd5b8035906020019184600183028401116401000000008311171561027c57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050610545565b005b60008054905090565b7f617cf8a4400dd7963ed519ebe655a16e8da1282bb8fea36a21f634af912f54ab6040518080602001828103825260158152602001807fefbfbdefbfbdefbfbdefbfbdefbfbdefbfbdefbfbd000000000000000000000081525060200191505060405180910390a1565b6040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260148152602001807f524556455254454420574954482052455645525400000000000000000000000081525060200191505060405180910390fd5b8060008190555050565b7f82dd7094dfd71d508c7a8ff013f3064664025068543bf228f7194a862cdfe3d7816040518080602001828103825283818151815260200191508051906020019080838360005b8381101561041d578082015181840152602081019050610402565b50505050905090810190601f16801561044a5780820380516001836020036101000a031916815260200191505b509250505060405180910390a150565b60006104ce576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260158152602001807f524556455254454420574954482052455155495245000000000000000000000081525060200191505060405180910390fd5b565b807f929af6b98ce8455e51b1e90cceeeec03ce38d7c7396f1f0b0233d043c898a29c83604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a25050565b600061054357600080fd5b565b7f617cf8a4400dd7963ed519ebe655a16e8da1282bb8fea36a21f634af912f54ab816040518080602001828103825283818151815260200191508051906020019080838360005b838110156105a757808201518184015260208101905061058c565b50505050905090810190601f1680156105d45780820380516001836020036101000a031916815260200191505b509250505060405180910390a15056fea265627a7a7231582069bac219e1bd2bb93a98f42a0d7aa83ba402f2168ab48df5ba385e348b9b3e8864736f6c634300050f0032",
"linkReferences": {},
"deployedLinkReferences": {}
}
13 changes: 13 additions & 0 deletions test/sources/Basic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ contract Basic {

uint value;
event BasicEvent(address addr, uint indexed val);
event StringEvent(string str);
event IndexedStringEvent(string str);

function getValue() public view returns (uint val) {
return value;
Expand All @@ -32,4 +34,15 @@ contract Basic {
emit BasicEvent(addr, val);
}

function firesStringEvent(string memory _str) public {
emit StringEvent(_str);
}

function firesIndexedStringEvent(string memory _str) public {
emit IndexedStringEvent(_str);
}

function firesIllegalUtf8StringEvent() public {
emit StringEvent('�������');
}
}

0 comments on commit 43ef593

Please sign in to comment.