Created
February 7, 2020 12:35
-
-
Save igor-egorov/96dec21edc237327eaf92cbc83d78bd6 to your computer and use it in GitHub Desktop.
array and multimap gist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package adt_test | |
import ( | |
"context" | |
"encoding/hex" | |
"fmt" | |
"github.com/filecoin-project/specs-actors/actors/util/adt" | |
block "github.com/ipfs/go-block-format" | |
cid "github.com/ipfs/go-cid" | |
cbor "github.com/ipfs/go-ipld-cbor" | |
"testing" | |
) | |
type mockBlocks struct { | |
data map[cid.Cid]block.Block | |
} | |
func newMockBlocks() *mockBlocks { | |
return &mockBlocks{make(map[cid.Cid]block.Block)} | |
} | |
func (mb *mockBlocks) Get(c cid.Cid) (block.Block, error) { | |
d, ok := mb.data[c] | |
if ok { | |
return d, nil | |
} | |
return nil, fmt.Errorf("Not Found") | |
} | |
func (mb *mockBlocks) Put(b block.Block) error { | |
mb.data[b.Cid()] = b | |
return nil | |
} | |
type aaa struct { | |
cbor.BasicIpldStore | |
} | |
func (mb *aaa) Context() context.Context { | |
return context.Background() | |
} | |
func Test(t *testing.T) { | |
var arr, _ = adt.MakeEmptyArray(&aaa{*cbor.NewCborStore(newMockBlocks())}) | |
root := arr.Root() | |
fmt.Printf("%v\n", hex.EncodeToString(root.Bytes())) | |
var mmap, _ = adt.MakeEmptyMultiap(&aaa{*cbor.NewCborStore(newMockBlocks())}) | |
root = mmap.Root() | |
fmt.Printf("%v\n", hex.EncodeToString(root.Bytes())) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment