-
Notifications
You must be signed in to change notification settings - Fork 189
/
Copy pathkvstore_test.go
45 lines (41 loc) · 1.37 KB
/
kvstore_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
package protocol
import (
"math/rand"
"testing"
clone "github.com/huandu/go-clone/generic"
"github.com/onflow/go-ethereum/rlp"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestExecutionMeteringParameters_EncodeRLP tests properties of the custom RLP encoding logic.
func TestExecutionMeteringParameters_EncodeRLP(t *testing.T) {
params1 := &ExecutionMeteringParameters{
ExecutionMemoryLimit: rand.Uint64(),
ExecutionMemoryWeights: make(map[uint32]uint64, 10),
ExecutionEffortWeights: make(map[uint32]uint64, 10),
}
for range 10 {
params1.ExecutionMemoryWeights[rand.Uint32()] = rand.Uint64()
params1.ExecutionEffortWeights[rand.Uint32()] = rand.Uint64()
}
t.Run("deterministic encoding", func(t *testing.T) {
enc1, err := rlp.EncodeToBytes(params1)
require.NoError(t, err)
enc2, err := rlp.EncodeToBytes(params1)
require.NoError(t, err)
assert.Equal(t, enc1, enc2)
})
t.Run("unique encoding", func(t *testing.T) {
params2 := clone.Clone(params1)
for k, v := range params2.ExecutionMemoryWeights {
params2.ExecutionMemoryWeights[k] = v + 1
assert.NotEqual(t, params1.ExecutionMemoryWeights[k], params2.ExecutionMemoryWeights[k])
break
}
enc1, err := rlp.EncodeToBytes(params1)
require.NoError(t, err)
enc2, err := rlp.EncodeToBytes(params2)
require.NoError(t, err)
assert.NotEqual(t, enc1, enc2)
})
}