| 11 | ) |
| 12 | |
| 13 | func TestBasic(t *testing.T) { |
| 14 | ctx := context.Background() |
| 15 | |
| 16 | const numAccounts = 1 |
| 17 | const autoCommit = true |
| 18 | var accountBalance = big.NewInt(100) |
| 19 | |
| 20 | backend, err := ethereum.CreateSimulatedBackend(numAccounts, autoCommit, accountBalance) |
| 21 | if err != nil { |
| 22 | t.Fatalf("unable to create simulated backend: %s", err) |
| 23 | } |
| 24 | defer backend.Close() |
| 25 | |
| 26 | clt, err := ethereum.NewClient(backend, backend.PrivateKeys[0]) |
| 27 | if err != nil { |
| 28 | t.Fatalf("unable to create ethereum api: %s", err) |
| 29 | } |
| 30 | |
| 31 | // ========================================================================= |
| 32 | |
| 33 | const gasLimit = 1600000 |
| 34 | valueGwei := big.NewFloat(0.0) |
| 35 | gasPrice := currency.GWei2Wei(big.NewFloat(39.576)) |
| 36 | tranOpts, err := clt.NewTransactOpts(ctx, gasLimit, gasPrice, valueGwei) |
| 37 | if err != nil { |
| 38 | t.Fatalf("unable to create transaction opts for deploy: %s", err) |
| 39 | } |
| 40 | |
| 41 | contractID, tx, _, err := basic.DeployBasic(tranOpts, clt.Backend) |
| 42 | if err != nil { |
| 43 | t.Fatalf("unable to deploy basic: %s", err) |
| 44 | } |
| 45 | |
| 46 | if _, err := clt.WaitMined(ctx, tx); err != nil { |
| 47 | t.Fatalf("waiting for deploy: %s", err) |
| 48 | } |
| 49 | |
| 50 | testBasic, err := basic.NewBasic(contractID, clt.Backend) |
| 51 | if err != nil { |
| 52 | t.Fatalf("error creating basic: %s", err) |
| 53 | } |
| 54 | |
| 55 | // ========================================================================= |
| 56 | |
| 57 | callOpts, err := clt.NewCallOpts(ctx) |
| 58 | if err != nil { |
| 59 | t.Fatalf("unable to create call opts: %s", err) |
| 60 | } |
| 61 | |
| 62 | ver, err := testBasic.Version(callOpts) |
| 63 | if err != nil { |
| 64 | t.Fatalf("unable to get version: %s", err) |
| 65 | } |
| 66 | |
| 67 | if ver != "1.1" { |
| 68 | t.Fatalf("should be able to get the correct version, got %s exp %s", ver, "1.1") |
| 69 | } |
| 70 | |