Closed
Description
Solidity allows developers to define some event with anonymous arguments. But the abi
library can't resolve this type of log correctly.
Testing contract
pragma solidity >=0.6.0 <0.7.0;
contract MyContract {
event MyEvent(address);
function foo() public {
emit MyEvent(msg.sender);
}
}
Testing scripts
package anno
import (
"math/big"
"testing"
"time"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/crypto"
)
func TestAnno(t *testing.T) {
key, _ := crypto.GenerateKey()
addr := crypto.PubkeyToAddress(key.PublicKey)
sim := backends.NewSimulatedBackend(core.GenesisAlloc{addr: {Balance: big.NewInt(1000000000)}}, 10000000)
defer sim.Close()
opts := bind.NewKeyedTransactor(key)
_, _, c, err := DeployAnno(opts, sim)
if err != nil {
t.Error("Failed to deploy contract", err)
}
sim.Commit()
shutdown := make(chan struct{})
defer close(shutdown)
verifier := make(chan struct{}, 1)
go func() {
sink := make(chan *AnnoMyEvent)
sub, err := c.WatchMyEvent(nil, sink)
if err != nil {
t.Errorf("Failed to monitor event %v", err)
return
}
defer sub.Unsubscribe()
select {
case <-shutdown:
return
case <-sink:
verifier <- struct{}{}
}
}()
c.Foo(opts)
sim.Commit()
select {
case <-verifier:
return
case <-time.After(time.Second):
t.Fatalf("No event arrives")
}
}
Expected behaviour
The unit test above should be able to pass
Actual behaviour
Failed
Steps to reproduce the behaviour
- Compile the solidity code
- Generate go-binding via
abigen
- Run the scripts above
Metadata
Assignees
Labels
No labels
Activity