-
Notifications
You must be signed in to change notification settings - Fork 0
/
logicid_test.go
67 lines (52 loc) · 1.67 KB
/
logicid_test.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package identifiers
import (
"encoding/json"
"fmt"
"testing"
"github.com/google/gofuzz"
"github.com/stretchr/testify/require"
)
func TestLogicIDv0(t *testing.T) {
// Setup fuzzer
f := fuzz.New().NilChance(0)
type params struct {
Persistent bool
Ephemeral bool
Interactive bool
AssetLogic bool
Edition uint16
Address Address
}
var x params
for i := 0; i < 1000; i++ {
// Fuzz Parameters
f.Fuzz(&x)
// Create new LogicID
logicID := NewLogicIDv0(x.Persistent, x.Ephemeral, x.Interactive, x.AssetLogic, x.Edition, x.Address)
require.Equal(t, x.Address, logicID.Address())
// Check type conversions
require.Equal(t, "0x"+string(logicID), logicID.String())
require.Equal(t, must(decodeHexString(string(logicID))), logicID.Bytes())
// Check identifier conversion
identifier, err := logicID.Identifier()
require.NoError(t, err)
// Check encoded parameter accessors
require.Equal(t, 0, identifier.Version())
require.Equal(t, logicID, identifier.LogicID())
require.Equal(t, x.Persistent, identifier.HasPersistentState())
require.Equal(t, x.Ephemeral, identifier.HasEphemeralState())
require.Equal(t, x.Interactive, identifier.HasInteractableSites())
require.Equal(t, x.AssetLogic, identifier.AssetLogic())
require.Equal(t, uint64(x.Edition), identifier.Edition())
require.Equal(t, x.Address, identifier.Address())
// Check serialization
encoded, err := json.Marshal(logicID)
require.NoError(t, err)
require.Equal(t, fmt.Sprintf(`"0x%v"`, string(logicID)), string(encoded))
// Check deserialization
var decoded LogicID
err = json.Unmarshal(encoded, &decoded)
require.NoError(t, err)
require.Equal(t, logicID, decoded)
}
}