diff --git a/execution/evm/abi/abi.go b/execution/evm/abi/abi.go index 3879bb8a89b292e3a45f0be857181c6b597121a0..d0d71eb8162821f30eeeb53c774bfc27e466a12e 100644 --- a/execution/evm/abi/abi.go +++ b/execution/evm/abi/abi.go @@ -874,7 +874,7 @@ func ReadAbiSpec(specBytes []byte) (*AbiSpec, error) { inputs[i].EVM = EVMBytes{M: 32} } } - abiSpec.Events[s.Name] = Event{Inputs: inputs} + abiSpec.Events[s.Name] = Event{Inputs: inputs, Anonymous: s.Anonymous} case "function": inputs, err := readArgSpec(s.Inputs) if err != nil { diff --git a/execution/solidity/event_emitter.sol b/execution/solidity/event_emitter.sol new file mode 100644 index 0000000000000000000000000000000000000000..3ab387b46ae77bb183d8eeda962557c8e2e49fe2 --- /dev/null +++ b/execution/solidity/event_emitter.sol @@ -0,0 +1,16 @@ +pragma solidity ^0.4.16; + +contract EventEmitter { + // indexed puts it in topic + event ManyTypes( + bytes32 indexed direction, + bool trueism, + string german , + int indexed newDepth, + string indexed hash) + anonymous; + + function EmitOne() public { + emit ManyTypes("Downsie!", true, "Donaudampfschifffahrtselektrizitätenhauptbetriebswerkbauunterbeamtengesellschaft", 102, 'hash'); + } +} \ No newline at end of file diff --git a/execution/solidity/event_emitter.sol.go b/execution/solidity/event_emitter.sol.go new file mode 100644 index 0000000000000000000000000000000000000000..b47c23f0666906d402b248ce549eefe76937d0ea --- /dev/null +++ b/execution/solidity/event_emitter.sol.go @@ -0,0 +1,6 @@ +package solidity + +import "github.com/tmthrgd/go-hex" + +var Bytecode_EventEmitter = hex.MustDecodeString("6080604052348015600f57600080fd5b506101848061001f6000396000f300608060405260043610610041576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063e8e49a7114610046575b600080fd5b34801561005257600080fd5b5061005b61005d565b005b60405180807f68617368000000000000000000000000000000000000000000000000000000008152506004019050604051809103902060667f446f776e736965210000000000000000000000000000000000000000000000006001604051808215151515815260200180602001828103825260518152602001807f446f6e617564616d7066736368696666666168727473656c656b7472697a697481526020017fc3a474656e686175707462657472696562737765726b626175756e746572626581526020017f616d74656e676573656c6c7363686166740000000000000000000000000000008152506060019250505060405180910390a35600a165627a7a72305820f3fba03c463579cc5b976d8a660fbecb3b45a67db1f160f999901b0b3822aa840029") +var Abi_EventEmitter = []byte(`[{"constant":false,"inputs":[],"name":"EmitOne","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"anonymous":true,"inputs":[{"indexed":true,"name":"direction","type":"bytes32"},{"indexed":false,"name":"trueism","type":"bool"},{"indexed":false,"name":"german","type":"string"},{"indexed":true,"name":"newDepth","type":"int256"},{"indexed":true,"name":"hash","type":"string"}],"name":"ManyTypes","type":"event"}]`) diff --git a/integration/rpctransact/call_test.go b/integration/rpctransact/call_test.go index 4937943ffb0e7f2f6bfcf6f29bab3bd095da068b..490267981a62d8332f7b3a93310a88d63f4f80cd 100644 --- a/integration/rpctransact/call_test.go +++ b/integration/rpctransact/call_test.go @@ -14,6 +14,7 @@ import ( "github.com/hyperledger/burrow/execution/evm/abi" "github.com/hyperledger/burrow/execution/evm/asm" "github.com/hyperledger/burrow/execution/evm/asm/bc" + "github.com/hyperledger/burrow/execution/evm/sha3" "github.com/hyperledger/burrow/execution/exec" "github.com/hyperledger/burrow/execution/solidity" "github.com/hyperledger/burrow/integration/rpctest" @@ -286,6 +287,36 @@ func TestLogEvents(t *testing.T) { assert.Equal(t, "Upsie!", direction) } +func TestEventEmitter(t *testing.T) { + cli := rpctest.NewTransactClient(t, testConfig.RPC.GRPC.ListenAddress) + createTxe := rpctest.CreateContract(t, cli, inputAddress, solidity.Bytecode_EventEmitter) + address := lastCall(createTxe.Events).CallData.Callee + spec, err := abi.ReadAbiSpec(solidity.Abi_EventEmitter) + require.NoError(t, err) + data, err := spec.Pack("EmitOne") + require.NoError(t, err) + callTxe := rpctest.CallContract(t, cli, inputAddress, address, data) + evs := filterLogs(callTxe.Events) + log := evs[0] + var direction string + var truism bool + var depth int64 + var german string + var hash []byte + err = abi.UnpackEvent(spec.Events["ManyTypes"], log.Topics, log.Data.Bytes(), &direction, &truism, &german, &depth, &hash) + require.NoError(t, err) + + h := sha3.NewKeccak256() + h.Write([]byte("hash")) + expectedHash := h.Sum(nil) + // "Downsie!", true, "Donaudampfschifffahrtselektrizitätenhauptbetriebswerkbauunterbeamtengesellschaft", 102, [0xcd, 0x9a, 0xf3], 'hash') + assert.Equal(t, "Downsie!", direction) + assert.Equal(t, true, truism) + assert.Equal(t, "Donaudampfschifffahrtselektrizitätenhauptbetriebswerkbauunterbeamtengesellschaft", german) + assert.Equal(t, int64(102), depth) + assert.Equal(t, expectedHash, hash) +} + func TestRevert(t *testing.T) { cli := rpctest.NewTransactClient(t, testConfig.RPC.GRPC.ListenAddress) txe := rpctest.CreateContract(t, cli, inputAddress, solidity.Bytecode_Revert)