예제 #1
0
func TestDeploymentAndIntegration(t *testing.T) {
	// generate new key
	key := crypto.NewKey(rand.Reader)
	// init new simulated backend
	sim := backends.NewSimulatedBackend(core.GenesisAccount{Address: key.Address, Balance: big.NewInt(10000000000)})

	// created authenticator
	auth := bind.NewKeyedTransactor(key)

	// deploy the contract
	_, _, api, err := DeployEtherAPIs(auth, sim)

	// use a session based approach so that we do not need
	// to repass these settings all the time.
	session := &EtherAPIsSession{
		Contract: api,
		CallOpts: bind.CallOpts{
			Pending: true,
		},
		TransactOpts: bind.TransactOpts{
			From:     auth.From,
			Signer:   auth.Signer,
			GasLimit: big.NewInt(400000),
		},
	}

	// add a new service
	_, err = session.AddService("etherapis", "https://etherapis.io", big.NewInt(0), big.NewInt(10), big.NewInt(432000))
	if err != nil {
		t.Error(err)
	}

	// retrieve the service
	service, err := session.GetService(big.NewInt(0))
	if err != nil {
		t.Fatal(err)
	}
	if service.Enabled {
		t.Error("expected service to be disabled")
	}

	// enable the service
	_, err = session.EnableService(big.NewInt(0))
	if err != nil {
		t.Fatal(err)
	}
	service, err = session.GetService(big.NewInt(0))
	if err != nil {
		t.Fatal(err)
	}
	if !service.Enabled {
		t.Error("expected service to be enabled")
	}

	// flag deletion
	_, err = session.DeleteService(big.NewInt(0))
	if err != nil {
		t.Fatal(err)
	}

	service, err = session.GetService(big.NewInt(0))
	if err != nil {
		t.Fatal(err)
	}
	if !service.Deleted {
		t.Error("expected service to be deleted")
	}
}
예제 #2
0
	"github.com/ethereum/go-ethereum/common"
	"github.com/ethereum/go-ethereum/core"
	"github.com/ethereum/go-ethereum/core/types"
	"github.com/ethereum/go-ethereum/crypto"
	"github.com/ethereum/go-ethereum/ethdb"
	"github.com/ethereum/go-ethereum/event"
	"github.com/ethereum/go-ethereum/p2p"
	"github.com/ethereum/go-ethereum/p2p/discover"
)

func init() {
	// glog.SetToStderr(true)
	// glog.SetV(6)
}

var testAccount = crypto.NewKey(rand.Reader)

func TestStatusMsgErrors(t *testing.T) {
	pm := newProtocolManagerForTesting(nil)
	td, currentBlock, genesis := pm.chainman.Status()
	defer pm.Stop()

	tests := []struct {
		code      uint64
		data      interface{}
		wantError error
	}{
		{
			code: TxMsg, data: []interface{}{},
			wantError: errResp(ErrNoStatusMsg, "first msg has code 2 (!= 0)"),
		},