TestReadWrite tests a basic eth storage read/write
(t *testing.T)
| 733 | |
| 734 | // TestReadWrite tests a basic eth storage read/write |
| 735 | func 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; |
nothing calls this directly
no test coverage detected