2022-08-29 14:25:30 +00:00
|
|
|
// stm: #unit
|
2020-09-17 02:13:12 +00:00
|
|
|
package adt
|
2020-07-07 22:26:33 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
2022-06-14 15:00:51 +00:00
|
|
|
cbornode "github.com/ipfs/go-ipld-cbor"
|
2020-07-07 22:26:33 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
typegen "github.com/whyrusleeping/cbor-gen"
|
|
|
|
|
2020-09-14 20:31:03 +00:00
|
|
|
"github.com/filecoin-project/go-state-types/abi"
|
2020-10-08 01:09:33 +00:00
|
|
|
builtin2 "github.com/filecoin-project/specs-actors/v2/actors/builtin"
|
|
|
|
adt2 "github.com/filecoin-project/specs-actors/v2/actors/util/adt"
|
2020-07-23 02:05:11 +00:00
|
|
|
|
2021-01-29 20:01:00 +00:00
|
|
|
bstore "github.com/filecoin-project/lotus/blockstore"
|
2020-07-07 22:26:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestDiffAdtArray(t *testing.T) {
|
|
|
|
ctxstoreA := newContextStore()
|
|
|
|
ctxstoreB := newContextStore()
|
|
|
|
|
2020-10-08 01:09:33 +00:00
|
|
|
arrA := adt2.MakeEmptyArray(ctxstoreA)
|
|
|
|
arrB := adt2.MakeEmptyArray(ctxstoreB)
|
2020-07-07 22:26:33 +00:00
|
|
|
|
2020-10-08 01:09:33 +00:00
|
|
|
require.NoError(t, arrA.Set(0, builtin2.CBORBytes([]byte{0}))) // delete
|
2020-07-07 22:26:33 +00:00
|
|
|
|
2020-10-08 01:09:33 +00:00
|
|
|
require.NoError(t, arrA.Set(1, builtin2.CBORBytes([]byte{0}))) // modify
|
|
|
|
require.NoError(t, arrB.Set(1, builtin2.CBORBytes([]byte{1})))
|
2020-07-07 22:26:33 +00:00
|
|
|
|
2020-10-08 01:09:33 +00:00
|
|
|
require.NoError(t, arrA.Set(2, builtin2.CBORBytes([]byte{1}))) // delete
|
2020-07-07 22:26:33 +00:00
|
|
|
|
2020-10-08 01:09:33 +00:00
|
|
|
require.NoError(t, arrA.Set(3, builtin2.CBORBytes([]byte{0}))) // noop
|
|
|
|
require.NoError(t, arrB.Set(3, builtin2.CBORBytes([]byte{0})))
|
2020-07-07 22:26:33 +00:00
|
|
|
|
2020-10-08 01:09:33 +00:00
|
|
|
require.NoError(t, arrA.Set(4, builtin2.CBORBytes([]byte{0}))) // modify
|
|
|
|
require.NoError(t, arrB.Set(4, builtin2.CBORBytes([]byte{6})))
|
2020-07-07 22:26:33 +00:00
|
|
|
|
2020-10-08 01:09:33 +00:00
|
|
|
require.NoError(t, arrB.Set(5, builtin2.CBORBytes{8})) // add
|
|
|
|
require.NoError(t, arrB.Set(6, builtin2.CBORBytes{9})) // add
|
2020-07-07 22:26:33 +00:00
|
|
|
|
2020-08-12 23:44:09 +00:00
|
|
|
changes := new(TestDiffArray)
|
2020-07-07 22:26:33 +00:00
|
|
|
|
feat: Add additional test annotations (#8272)
* Annotate api,proxy_util,blockstore_badger, policy tests
* Annotate splitstore: bsbadger / markset
* Annotate splitstore feature
* Annotate union/timed blockstore tests
* Annotate openrpc, diff_adt tests
* Annotate error,drand,events tests
* Annotate predicates_test
* Fix annotations
* Annotate tscache, gen tests
* Annotate fundmanager test
* Annotate repub and selection tests
* Annotate statetree_test
* Annotate forks_test
* Annotate searchwait_test.go
* Fix duplicated @@ symbols
* Annotate chain stmgr/store tests
* Annotate more (types) tests
* More tests annotated
* Annotate conformance chaos actor tests
* Annotate more integration tests
* Annotate journal system tests
* Annotate more tests.
* Annotate gas,head buffer behaviors
* Fix markset annotations
* doc: test annotations for the markets dagstore wrapper
* Annotate miner_api test in dagstore
* Annotate more test files
* Remove bad annotations from fsrepo
* Annotate wdpost system
* Remove bad annotations
* Renamce "conformance" to "chaos_actor" tests
* doc: stm annotations for blockheader & election proof tests
* Annotate remaining "A" tests
* annotate: stm for error_test
* memrepo_test.go
* Annotate "b" file tests
* message_test.go
* doc: stm annotate for fsrepo_test
* Annotate "c" file tests
* Annotate "D" test files
* message_test.go
* doc: stm annotate for chain, node/config & client
* docs: stm annotate node_test
* Annotate u,v,wl tests
* doc: stm annotations for various test files
* Annotate "T" test files
* doc: stm annotate for proxy_util_test & policy_test
* doc: stm annotate for various tests
* doc: final few stm annotations
* Add mempool unit tests
* Add two more memPool Add tests
* Update submodules
* Add check function tests
* Add stm annotations, refactor test helper
* Annotate api,proxy_util,blockstore_badger, policy tests
* Annotate splitstore: bsbadger / markset
solving merge conflicts
* Annotate splitstore feature
* Annotate union/timed blockstore tests
* Annotate openrpc, diff_adt tests
* Annotate error,drand,events tests
* Annotate predicates_test
* Fix annotations
* Annotate tscache, gen tests
* Annotate fundmanager test
* Annotate statetree_test
* Annotate forks_test
* Annotate searchwait_test.go
* Fix duplicated @@ symbols
* Annotate chain stmgr/store tests
* Annotate more (types) tests
* More tests annotated
* Annotate conformance chaos actor tests
* Annotate more integration tests
* Annotate journal system tests
* Annotate more tests.
* Annotate gas,head buffer behaviors
solve merge conflict
* Fix markset annotations
* Annotate miner_api test in dagstore
* Annotate more test files
* doc: test annotations for the markets dagstore wrapper
* Annotate wdpost system
* Renamce "conformance" to "chaos_actor" tests
* Annotate remaining "A" tests
* doc: stm annotations for blockheader & election proof tests
* annotate: stm for error_test
* Annotate "b" file tests
* memrepo_test.go
* Annotate "c" file tests
* message_test.go
* Annotate "D" test files
* doc: stm annotate for fsrepo_test
* Annotate u,v,wl tests
* message_test.go
* doc: stm annotate for chain, node/config & client
* docs: stm annotate node_test
* Annotate "T" test files
* doc: stm annotations for various test files
* Add mempool unit tests
solve merge conflict
* doc: stm annotate for proxy_util_test & policy_test
* doc: stm annotate for various tests
* doc: final few stm annotations
* Add two more memPool Add tests
* Update submodules
* Add check function tests
solve conflict
* Add stm annotations, refactor test helper
solve merge conflict
* Change CLI test kinds to "unit"
* Fix double merged test
* Fix ccupgrade_test merge
* Fix lint issues
* Add stm annotation to types_Test
* Test vectors submodule
* Add file annotation to burn_test
Co-authored-by: Nikola Divic <divicnikola@gmail.com>
Co-authored-by: TheMenko <themenkoprojects@gmail.com>
2022-03-16 17:37:34 +00:00
|
|
|
//stm: @CHAIN_ADT_ARRAY_DIFF_001
|
2020-07-07 22:26:33 +00:00
|
|
|
assert.NoError(t, DiffAdtArray(arrA, arrB, changes))
|
|
|
|
assert.NotNil(t, changes)
|
|
|
|
|
|
|
|
assert.Equal(t, 2, len(changes.Added))
|
2020-07-08 00:44:55 +00:00
|
|
|
// keys 5 and 6 were added
|
|
|
|
assert.EqualValues(t, uint64(5), changes.Added[0].key)
|
|
|
|
assert.EqualValues(t, []byte{8}, changes.Added[0].val)
|
|
|
|
assert.EqualValues(t, uint64(6), changes.Added[1].key)
|
|
|
|
assert.EqualValues(t, []byte{9}, changes.Added[1].val)
|
2020-07-07 22:26:33 +00:00
|
|
|
|
|
|
|
assert.Equal(t, 2, len(changes.Modified))
|
2020-07-08 00:44:55 +00:00
|
|
|
// keys 1 and 4 were modified
|
|
|
|
assert.EqualValues(t, uint64(1), changes.Modified[0].From.key)
|
|
|
|
assert.EqualValues(t, []byte{0}, changes.Modified[0].From.val)
|
|
|
|
assert.EqualValues(t, uint64(1), changes.Modified[0].To.key)
|
|
|
|
assert.EqualValues(t, []byte{1}, changes.Modified[0].To.val)
|
|
|
|
assert.EqualValues(t, uint64(4), changes.Modified[1].From.key)
|
|
|
|
assert.EqualValues(t, []byte{0}, changes.Modified[1].From.val)
|
|
|
|
assert.EqualValues(t, uint64(4), changes.Modified[1].To.key)
|
|
|
|
assert.EqualValues(t, []byte{6}, changes.Modified[1].To.val)
|
2020-07-07 22:26:33 +00:00
|
|
|
|
|
|
|
assert.Equal(t, 2, len(changes.Removed))
|
2020-07-08 00:44:55 +00:00
|
|
|
// keys 0 and 2 were deleted
|
|
|
|
assert.EqualValues(t, uint64(0), changes.Removed[0].key)
|
|
|
|
assert.EqualValues(t, []byte{0}, changes.Removed[0].val)
|
|
|
|
assert.EqualValues(t, uint64(2), changes.Removed[1].key)
|
|
|
|
assert.EqualValues(t, []byte{1}, changes.Removed[1].val)
|
|
|
|
}
|
|
|
|
|
2020-08-12 23:44:09 +00:00
|
|
|
func TestDiffAdtMap(t *testing.T) {
|
|
|
|
ctxstoreA := newContextStore()
|
|
|
|
ctxstoreB := newContextStore()
|
|
|
|
|
2020-10-08 01:09:33 +00:00
|
|
|
mapA := adt2.MakeEmptyMap(ctxstoreA)
|
|
|
|
mapB := adt2.MakeEmptyMap(ctxstoreB)
|
2020-08-12 23:44:09 +00:00
|
|
|
|
2020-10-08 01:09:33 +00:00
|
|
|
require.NoError(t, mapA.Put(abi.UIntKey(0), builtin2.CBORBytes([]byte{0}))) // delete
|
2020-08-12 23:44:09 +00:00
|
|
|
|
2020-10-08 01:09:33 +00:00
|
|
|
require.NoError(t, mapA.Put(abi.UIntKey(1), builtin2.CBORBytes([]byte{0}))) // modify
|
|
|
|
require.NoError(t, mapB.Put(abi.UIntKey(1), builtin2.CBORBytes([]byte{1})))
|
2020-08-12 23:44:09 +00:00
|
|
|
|
2020-10-08 01:09:33 +00:00
|
|
|
require.NoError(t, mapA.Put(abi.UIntKey(2), builtin2.CBORBytes([]byte{1}))) // delete
|
2020-08-12 23:44:09 +00:00
|
|
|
|
2020-10-08 01:09:33 +00:00
|
|
|
require.NoError(t, mapA.Put(abi.UIntKey(3), builtin2.CBORBytes([]byte{0}))) // noop
|
|
|
|
require.NoError(t, mapB.Put(abi.UIntKey(3), builtin2.CBORBytes([]byte{0})))
|
2020-08-12 23:44:09 +00:00
|
|
|
|
2020-10-08 01:09:33 +00:00
|
|
|
require.NoError(t, mapA.Put(abi.UIntKey(4), builtin2.CBORBytes([]byte{0}))) // modify
|
|
|
|
require.NoError(t, mapB.Put(abi.UIntKey(4), builtin2.CBORBytes([]byte{6})))
|
2020-08-12 23:44:09 +00:00
|
|
|
|
2020-10-08 01:09:33 +00:00
|
|
|
require.NoError(t, mapB.Put(abi.UIntKey(5), builtin2.CBORBytes{8})) // add
|
|
|
|
require.NoError(t, mapB.Put(abi.UIntKey(6), builtin2.CBORBytes{9})) // add
|
2020-08-12 23:44:09 +00:00
|
|
|
|
|
|
|
changes := new(TestDiffMap)
|
|
|
|
|
feat: Add additional test annotations (#8272)
* Annotate api,proxy_util,blockstore_badger, policy tests
* Annotate splitstore: bsbadger / markset
* Annotate splitstore feature
* Annotate union/timed blockstore tests
* Annotate openrpc, diff_adt tests
* Annotate error,drand,events tests
* Annotate predicates_test
* Fix annotations
* Annotate tscache, gen tests
* Annotate fundmanager test
* Annotate repub and selection tests
* Annotate statetree_test
* Annotate forks_test
* Annotate searchwait_test.go
* Fix duplicated @@ symbols
* Annotate chain stmgr/store tests
* Annotate more (types) tests
* More tests annotated
* Annotate conformance chaos actor tests
* Annotate more integration tests
* Annotate journal system tests
* Annotate more tests.
* Annotate gas,head buffer behaviors
* Fix markset annotations
* doc: test annotations for the markets dagstore wrapper
* Annotate miner_api test in dagstore
* Annotate more test files
* Remove bad annotations from fsrepo
* Annotate wdpost system
* Remove bad annotations
* Renamce "conformance" to "chaos_actor" tests
* doc: stm annotations for blockheader & election proof tests
* Annotate remaining "A" tests
* annotate: stm for error_test
* memrepo_test.go
* Annotate "b" file tests
* message_test.go
* doc: stm annotate for fsrepo_test
* Annotate "c" file tests
* Annotate "D" test files
* message_test.go
* doc: stm annotate for chain, node/config & client
* docs: stm annotate node_test
* Annotate u,v,wl tests
* doc: stm annotations for various test files
* Annotate "T" test files
* doc: stm annotate for proxy_util_test & policy_test
* doc: stm annotate for various tests
* doc: final few stm annotations
* Add mempool unit tests
* Add two more memPool Add tests
* Update submodules
* Add check function tests
* Add stm annotations, refactor test helper
* Annotate api,proxy_util,blockstore_badger, policy tests
* Annotate splitstore: bsbadger / markset
solving merge conflicts
* Annotate splitstore feature
* Annotate union/timed blockstore tests
* Annotate openrpc, diff_adt tests
* Annotate error,drand,events tests
* Annotate predicates_test
* Fix annotations
* Annotate tscache, gen tests
* Annotate fundmanager test
* Annotate statetree_test
* Annotate forks_test
* Annotate searchwait_test.go
* Fix duplicated @@ symbols
* Annotate chain stmgr/store tests
* Annotate more (types) tests
* More tests annotated
* Annotate conformance chaos actor tests
* Annotate more integration tests
* Annotate journal system tests
* Annotate more tests.
* Annotate gas,head buffer behaviors
solve merge conflict
* Fix markset annotations
* Annotate miner_api test in dagstore
* Annotate more test files
* doc: test annotations for the markets dagstore wrapper
* Annotate wdpost system
* Renamce "conformance" to "chaos_actor" tests
* Annotate remaining "A" tests
* doc: stm annotations for blockheader & election proof tests
* annotate: stm for error_test
* Annotate "b" file tests
* memrepo_test.go
* Annotate "c" file tests
* message_test.go
* Annotate "D" test files
* doc: stm annotate for fsrepo_test
* Annotate u,v,wl tests
* message_test.go
* doc: stm annotate for chain, node/config & client
* docs: stm annotate node_test
* Annotate "T" test files
* doc: stm annotations for various test files
* Add mempool unit tests
solve merge conflict
* doc: stm annotate for proxy_util_test & policy_test
* doc: stm annotate for various tests
* doc: final few stm annotations
* Add two more memPool Add tests
* Update submodules
* Add check function tests
solve conflict
* Add stm annotations, refactor test helper
solve merge conflict
* Change CLI test kinds to "unit"
* Fix double merged test
* Fix ccupgrade_test merge
* Fix lint issues
* Add stm annotation to types_Test
* Test vectors submodule
* Add file annotation to burn_test
Co-authored-by: Nikola Divic <divicnikola@gmail.com>
Co-authored-by: TheMenko <themenkoprojects@gmail.com>
2022-03-16 17:37:34 +00:00
|
|
|
//stm: @CHAIN_ADT_MAP_DIFF_001
|
2020-08-12 23:44:09 +00:00
|
|
|
assert.NoError(t, DiffAdtMap(mapA, mapB, changes))
|
|
|
|
assert.NotNil(t, changes)
|
|
|
|
|
|
|
|
assert.Equal(t, 2, len(changes.Added))
|
|
|
|
// keys 5 and 6 were added
|
|
|
|
assert.EqualValues(t, uint64(6), changes.Added[0].key)
|
|
|
|
assert.EqualValues(t, []byte{9}, changes.Added[0].val)
|
|
|
|
assert.EqualValues(t, uint64(5), changes.Added[1].key)
|
|
|
|
assert.EqualValues(t, []byte{8}, changes.Added[1].val)
|
|
|
|
|
|
|
|
assert.Equal(t, 2, len(changes.Modified))
|
|
|
|
// keys 1 and 4 were modified
|
|
|
|
assert.EqualValues(t, uint64(1), changes.Modified[0].From.key)
|
|
|
|
assert.EqualValues(t, []byte{0}, changes.Modified[0].From.val)
|
|
|
|
assert.EqualValues(t, uint64(1), changes.Modified[0].To.key)
|
|
|
|
assert.EqualValues(t, []byte{1}, changes.Modified[0].To.val)
|
|
|
|
assert.EqualValues(t, uint64(4), changes.Modified[1].From.key)
|
|
|
|
assert.EqualValues(t, []byte{0}, changes.Modified[1].From.val)
|
|
|
|
assert.EqualValues(t, uint64(4), changes.Modified[1].To.key)
|
|
|
|
assert.EqualValues(t, []byte{6}, changes.Modified[1].To.val)
|
|
|
|
|
|
|
|
assert.Equal(t, 2, len(changes.Removed))
|
|
|
|
// keys 0 and 2 were deleted
|
|
|
|
assert.EqualValues(t, uint64(0), changes.Removed[0].key)
|
|
|
|
assert.EqualValues(t, []byte{0}, changes.Removed[0].val)
|
|
|
|
assert.EqualValues(t, uint64(2), changes.Removed[1].key)
|
|
|
|
assert.EqualValues(t, []byte{1}, changes.Removed[1].val)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
type TestDiffMap struct {
|
2020-08-13 11:44:43 +00:00
|
|
|
Added []adtMapDiffResult
|
2020-08-12 23:44:09 +00:00
|
|
|
Modified []TestAdtMapDiffModified
|
2020-08-13 11:44:43 +00:00
|
|
|
Removed []adtMapDiffResult
|
2020-08-12 23:44:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var _ AdtMapDiff = &TestDiffMap{}
|
|
|
|
|
2020-09-14 20:31:03 +00:00
|
|
|
func (t *TestDiffMap) AsKey(key string) (abi.Keyer, error) {
|
|
|
|
k, err := abi.ParseUIntKey(key)
|
2020-08-12 23:44:09 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-09-14 20:31:03 +00:00
|
|
|
return abi.UIntKey(k), nil
|
2020-08-12 23:44:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (t *TestDiffMap) Add(key string, val *typegen.Deferred) error {
|
2020-10-08 01:09:33 +00:00
|
|
|
v := new(builtin2.CBORBytes)
|
2020-08-12 23:44:09 +00:00
|
|
|
err := v.UnmarshalCBOR(bytes.NewReader(val.Raw))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-09-14 20:31:03 +00:00
|
|
|
k, err := abi.ParseUIntKey(key)
|
2020-08-12 23:44:09 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
t.Added = append(t.Added, adtMapDiffResult{
|
|
|
|
key: k,
|
|
|
|
val: *v,
|
|
|
|
})
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *TestDiffMap) Modify(key string, from, to *typegen.Deferred) error {
|
2020-10-08 01:09:33 +00:00
|
|
|
vFrom := new(builtin2.CBORBytes)
|
2020-08-12 23:44:09 +00:00
|
|
|
err := vFrom.UnmarshalCBOR(bytes.NewReader(from.Raw))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-10-08 01:09:33 +00:00
|
|
|
vTo := new(builtin2.CBORBytes)
|
2020-08-12 23:44:09 +00:00
|
|
|
err = vTo.UnmarshalCBOR(bytes.NewReader(to.Raw))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-09-14 20:31:03 +00:00
|
|
|
k, err := abi.ParseUIntKey(key)
|
2020-08-12 23:44:09 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if !bytes.Equal(*vFrom, *vTo) {
|
|
|
|
t.Modified = append(t.Modified, TestAdtMapDiffModified{
|
|
|
|
From: adtMapDiffResult{
|
|
|
|
key: k,
|
|
|
|
val: *vFrom,
|
|
|
|
},
|
|
|
|
To: adtMapDiffResult{
|
|
|
|
key: k,
|
|
|
|
val: *vTo,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *TestDiffMap) Remove(key string, val *typegen.Deferred) error {
|
2020-10-08 01:09:33 +00:00
|
|
|
v := new(builtin2.CBORBytes)
|
2020-08-12 23:44:09 +00:00
|
|
|
err := v.UnmarshalCBOR(bytes.NewReader(val.Raw))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-09-14 20:31:03 +00:00
|
|
|
k, err := abi.ParseUIntKey(key)
|
2020-08-12 23:44:09 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
t.Removed = append(t.Removed, adtMapDiffResult{
|
|
|
|
key: k,
|
|
|
|
val: *v,
|
|
|
|
})
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type adtMapDiffResult struct {
|
|
|
|
key uint64
|
2020-10-08 01:09:33 +00:00
|
|
|
val builtin2.CBORBytes
|
2020-08-12 23:44:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type TestAdtMapDiffModified struct {
|
|
|
|
From adtMapDiffResult
|
2020-08-13 11:44:43 +00:00
|
|
|
To adtMapDiffResult
|
2020-08-12 23:44:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type adtArrayDiffResult struct {
|
2020-07-08 00:44:55 +00:00
|
|
|
key uint64
|
2020-10-08 01:09:33 +00:00
|
|
|
val builtin2.CBORBytes
|
2020-07-07 22:26:33 +00:00
|
|
|
}
|
|
|
|
|
2020-08-12 23:44:09 +00:00
|
|
|
type TestDiffArray struct {
|
|
|
|
Added []adtArrayDiffResult
|
|
|
|
Modified []TestAdtArrayDiffModified
|
|
|
|
Removed []adtArrayDiffResult
|
2020-07-07 22:26:33 +00:00
|
|
|
}
|
|
|
|
|
2020-08-12 23:44:09 +00:00
|
|
|
var _ AdtArrayDiff = &TestDiffArray{}
|
2020-07-07 22:26:33 +00:00
|
|
|
|
2020-08-12 23:44:09 +00:00
|
|
|
type TestAdtArrayDiffModified struct {
|
|
|
|
From adtArrayDiffResult
|
|
|
|
To adtArrayDiffResult
|
2020-07-07 22:26:33 +00:00
|
|
|
}
|
|
|
|
|
2020-08-12 23:44:09 +00:00
|
|
|
func (t *TestDiffArray) Add(key uint64, val *typegen.Deferred) error {
|
2020-10-08 01:09:33 +00:00
|
|
|
v := new(builtin2.CBORBytes)
|
2020-07-07 22:26:33 +00:00
|
|
|
err := v.UnmarshalCBOR(bytes.NewReader(val.Raw))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-08-12 23:44:09 +00:00
|
|
|
t.Added = append(t.Added, adtArrayDiffResult{
|
2020-07-08 00:44:55 +00:00
|
|
|
key: key,
|
|
|
|
val: *v,
|
|
|
|
})
|
2020-07-07 22:26:33 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-08-12 23:44:09 +00:00
|
|
|
func (t *TestDiffArray) Modify(key uint64, from, to *typegen.Deferred) error {
|
2020-10-08 01:09:33 +00:00
|
|
|
vFrom := new(builtin2.CBORBytes)
|
2020-07-07 22:26:33 +00:00
|
|
|
err := vFrom.UnmarshalCBOR(bytes.NewReader(from.Raw))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-10-08 01:09:33 +00:00
|
|
|
vTo := new(builtin2.CBORBytes)
|
2020-07-07 22:26:33 +00:00
|
|
|
err = vTo.UnmarshalCBOR(bytes.NewReader(to.Raw))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if !bytes.Equal(*vFrom, *vTo) {
|
2020-08-12 23:44:09 +00:00
|
|
|
t.Modified = append(t.Modified, TestAdtArrayDiffModified{
|
|
|
|
From: adtArrayDiffResult{
|
2020-07-08 00:44:55 +00:00
|
|
|
key: key,
|
|
|
|
val: *vFrom,
|
|
|
|
},
|
2020-08-12 23:44:09 +00:00
|
|
|
To: adtArrayDiffResult{
|
2020-07-08 00:44:55 +00:00
|
|
|
key: key,
|
|
|
|
val: *vTo,
|
|
|
|
},
|
2020-07-07 22:26:33 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-08-12 23:44:09 +00:00
|
|
|
func (t *TestDiffArray) Remove(key uint64, val *typegen.Deferred) error {
|
2020-10-08 01:09:33 +00:00
|
|
|
v := new(builtin2.CBORBytes)
|
2020-07-07 22:26:33 +00:00
|
|
|
err := v.UnmarshalCBOR(bytes.NewReader(val.Raw))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-08-12 23:44:09 +00:00
|
|
|
t.Removed = append(t.Removed, adtArrayDiffResult{
|
2020-07-08 00:44:55 +00:00
|
|
|
key: key,
|
|
|
|
val: *v,
|
|
|
|
})
|
2020-07-07 22:26:33 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-09-17 02:13:12 +00:00
|
|
|
func newContextStore() Store {
|
2020-07-07 22:26:33 +00:00
|
|
|
ctx := context.Background()
|
2021-01-29 23:17:25 +00:00
|
|
|
bs := bstore.NewMemorySync()
|
2020-07-07 22:26:33 +00:00
|
|
|
store := cbornode.NewCborStore(bs)
|
2020-09-17 02:13:12 +00:00
|
|
|
return WrapStore(ctx, store)
|
2020-07-07 22:26:33 +00:00
|
|
|
}
|