forked from OffchainLabs/nitro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
archiving_storage_service_test.go
68 lines (55 loc) · 1.75 KB
/
archiving_storage_service_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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2021-2022, Offchain Labs, Inc.
// For license information, see https://github.com/nitro/blob/master/LICENSE
package das
import (
"bytes"
"context"
"testing"
"time"
"github.com/offchainlabs/nitro/arbstate"
"github.com/offchainlabs/nitro/das/dastree"
)
func TestArchivingStorageService(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
futureTime := uint64(time.Now().Add(time.Hour).Unix())
val1 := []byte("First value")
hash1 := dastree.Hash(val1)
val2 := []byte("Second value")
hash2 := dastree.Hash(val2)
firstStorage := NewMemoryBackedStorageService(ctx)
archiveTo := NewMemoryBackedStorageService(ctx)
err := firstStorage.Put(ctx, val1, futureTime)
Require(t, err)
archServ, err := NewArchivingStorageService(ctx, firstStorage, archiveTo, 60*60)
Require(t, err)
// verify that archServ is a StorageService
var ss StorageService = archServ
_ = ss
result1, err1 := archServ.GetByHash(ctx, hash1)
err2 := archServ.Put(ctx, val2, futureTime)
// don't check results yet, in the hope that we call asdr.Close with some ops still in the archive queue
err3 := archServ.Close(ctx)
if !bytes.Equal(val1, result1) {
t.Fatal()
}
Require(t, err1)
Require(t, err2)
Require(t, err3)
result1, err1 = archiveTo.GetByHash(ctx, hash1)
if !bytes.Equal(val1, result1) {
t.Fatal()
}
Require(t, err1)
result2, err2 := archiveTo.GetByHash(ctx, hash2)
if !bytes.Equal(val2, result2) {
t.Fatal()
}
Require(t, err2)
// verify that an ArchivingSimpleDASReader is a DataAvailabilityReader
var firstSDR arbstate.DataAvailabilityReader = firstStorage
asdr, err := NewArchivingSimpleDASReader(ctx, firstSDR, archiveTo, 60*60)
Require(t, err)
var secondSDR arbstate.DataAvailabilityReader = asdr
_ = secondSDR
}