-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
fixtures.go
37 lines (28 loc) · 986 Bytes
/
fixtures.go
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
package cltest
import (
"encoding/json"
"testing"
"github.com/smartcontractkit/chainlink/core/store/models"
"github.com/ethereum/go-ethereum/core/types"
"github.com/stretchr/testify/require"
"github.com/tidwall/gjson"
)
// JSONFromFixture create models.JSON from file path
func JSONFromFixture(t *testing.T, path string) models.JSON {
return JSONFromBytes(t, MustReadFile(t, path))
}
// LogFromFixture create ethtypes.log from file path
func LogFromFixture(t *testing.T, path string) types.Log {
value := gjson.Get(string(MustReadFile(t, path)), "params.result")
var el types.Log
require.NoError(t, json.Unmarshal([]byte(value.String()), &el))
return el
}
// TxReceiptFromFixture create ethtypes.log from file path
func TxReceiptFromFixture(t *testing.T, path string) *types.Receipt {
jsonStr := JSONFromFixture(t, path).Get("result").String()
var receipt types.Receipt
err := json.Unmarshal([]byte(jsonStr), &receipt)
require.NoError(t, err)
return &receipt
}