This repository was archived by the owner on Oct 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcontract_test.go
More file actions
57 lines (44 loc) · 1.53 KB
/
contract_test.go
File metadata and controls
57 lines (44 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package ethertest_test
import (
"context"
"fmt"
"os"
"testing"
"time"
"github.com/ethereum/go-ethereum/core/types"
"github.com/stretchr/testify/require"
"github.com/tokencard/ethertest"
"github.com/tokencard/ethertest/test/bindings"
)
func TestContract(t *testing.T) {
var tr = ethertest.NewTestRig()
var owner = ethertest.NewAccount()
tr.AddGenesisAccountAllocation(owner.Address(), ethertest.EthToWei(100))
tr.AddCoverageForContracts("./test/build/test/combined.json", "test/contracts")
require := require.New(t)
be := tr.NewTestBackend(ethertest.WithBlockGasLimit(8000000), ethertest.WithBlockchainTime(time.Now().Add(-24*time.Hour)))
_, tx, testBinding, err := bindings.DeployTest(owner.TransactOpts(), be, "initial value")
require.Nil(err)
be.Commit()
receipt, err := be.TransactionReceipt(context.Background(), tx.Hash())
require.Nil(err)
require.Equal(types.ReceiptStatusSuccessful, receipt.Status)
tx, err = testBinding.SetValue(owner.TransactOpts(), "new value")
require.Nil(err)
be.Commit()
successful, err := ethertest.IsSuccessful(be, tx)
require.Nil(err)
require.True(successful)
require.Nil(be.Close())
value, err := testBinding.Value(nil)
require.Nil(err)
require.Equal("new value", value)
err = testBinding.WillFail(nil)
require.NotNil(err)
tr.SaveTrace(os.Stdout)
tr.ExpectMinimumCoverage("subdir/super.sol", 100.0)
tr.ExpectMinimumCoverage("test.sol", 100.0)
tr.PrintGasUsage(os.Stdout)
fmt.Println(tr.LastExecuted())
require.Equal(int64(2), be.Blockchain().CurrentHeader().Number.Int64())
}