Ejemplo n.º 1
0
// setupReleaseTest creates a blockchain simulator and deploys a version oracle
// contract for testing.
func setupReleaseTest(t *testing.T, prefund ...*ecdsa.PrivateKey) (*ecdsa.PrivateKey, *ReleaseOracle, *backends.SimulatedBackend) {
	// Generate a new random account and a funded simulator
	key, _ := crypto.GenerateKey()
	auth := bind.NewKeyedTransactor(key)

	accounts := []core.GenesisAccount{{Address: auth.From, Balance: big.NewInt(10000000000)}}
	for _, key := range prefund {
		accounts = append(accounts, core.GenesisAccount{Address: crypto.PubkeyToAddress(key.PublicKey), Balance: big.NewInt(10000000000)})
	}
	sim := backends.NewSimulatedBackend(accounts...)

	// Deploy a version oracle contract, commit and return
	_, _, oracle, err := DeployReleaseOracle(auth, sim, []common.Address{auth.From})
	if err != nil {
		t.Fatalf("Failed to deploy version contract: %v", err)
	}
	sim.Commit()

	return key, oracle, sim
}
Ejemplo n.º 2
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")
	}
}