MCPcopy Create free account
hub / github.com/ethstorage/es-node / TestReadWrite

Function TestReadWrite

ethstorage/p2p/protocol/sync_test.go:735–767  ·  view source on GitHub ↗

TestReadWrite tests a basic eth storage read/write

(t *testing.T)

Source from the content-addressed store, hash-verified

733
734// TestReadWrite tests a basic eth storage read/write
735func TestReadWrite(t *testing.T) {
736 var (
737 kvSize = defaultChunkSize
738 kvEntries = uint64(16)
739 val = make([]byte, kvSize)
740 )
741 shards, files := createEthStorage(contract, []uint64{0}, defaultChunkSize, kvSize, kvEntries, common.Address{}, defaultEncodeType)
742 if shards == nil {
743 t.Fatalf("createEthStorage failed")
744 }
745
746 defer func(files []string) {
747 for _, file := range files {
748 os.Remove(file)
749 }
750 }(files)
751
752 val[0] = 1
753 root, _ := prover.GetRoot(val, 1, 1)
754 commit := generateMetadata(root)
755 sm := ethstorage.ContractToShardManager[contract]
756 success, err := sm.TryWrite(0, val, commit)
757 if !success || err != nil {
758 t.Fatalf("failed to write")
759 }
760 rdata, success, err := sm.TryRead(0, 1, commit)
761 if !success || err != nil {
762 t.Fatalf("failed to read")
763 }
764 if !bytes.Equal([]byte{1}, rdata) {
765 t.Fatalf("failed to compare")
766 }
767}
768
769// testSync sync test with a general process:
770// 1. create a storage manager and a local node, then start the sync client;

Callers

nothing calls this directly

Calls 5

TryWriteMethod · 0.80
createEthStorageFunction · 0.70
generateMetadataFunction · 0.70
GetRootMethod · 0.65
TryReadMethod · 0.65

Tested by

no test coverage detected