Skip to content

Instantly share code, notes, and snippets.

@natemurthy
Last active December 19, 2018 09:11
Show Gist options
  • Save natemurthy/f17bd5b553989cfcddc06babd9cf541f to your computer and use it in GitHub Desktop.
Save natemurthy/f17bd5b553989cfcddc06babd9cf541f to your computer and use it in GitHub Desktop.
package main
import (
"math/big"
"testing"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/crypto"
"github.com/stretchr/testify/suite"
)
type HelloworldTestSuite struct {
suite.Suite
auth *bind.TransactOpts
address common.Address
gAlloc core.GenesisAlloc
sim *backends.SimulatedBackend
helloworld *Helloworld
}
func TestRunHelloworldSuite(t *testing.T) {
suite.Run(t, new(HelloworldTestSuite))
}
func (s *HelloworldTestSuite) SetupTest() {
key, _ := crypto.GenerateKey()
s.auth = bind.NewKeyedTransactor(key)
s.address = s.auth.From
s.gAlloc = map[common.Address]core.GenesisAccount{
s.address: {Balance: big.NewInt(10000000000)},
}
s.sim = backends.NewSimulatedBackend(s.gAlloc)
_, _, hw, e := DeployHelloworld(s.auth, s.sim)
s.helloworld = hw
s.Nil(e)
s.sim.Commit()
}
func (s *HelloworldTestSuite) TestSay() {
str, err := s.helloworld.Say(nil)
s.Equal("hello etherworld", str)
s.Nil(err)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment