@@ -4,6 +4,7 @@ package massifs
4
4
5
5
import (
6
6
"context"
7
+ "crypto/ecdsa"
7
8
"strings"
8
9
"testing"
9
10
@@ -18,45 +19,62 @@ type TestLocalReaderContext struct {
18
19
AzuriteContext mmrtesting.TestContext
19
20
TestConfig mmrtesting.TestConfig
20
21
CommitterConfig TestCommitterConfig
22
+ LogOptions TestLogOptions
21
23
22
24
G mmrtesting.TestGenerator
23
25
// We use a regular massif reader attached to azurite to test the local massif reader.
24
26
AzuriteReader MassifReader
25
27
}
26
28
27
- // TestLogCreatorContext holds the context data resulting from a call to CreateLog
29
+ // TestLogOptions holds the context data resulting from a call to CreateLog
28
30
// Unless one or more of the TEstCreateLogOptions are used, the context will not have anything interesting in it.
29
- type TestLogCreatorContext struct {
30
- Preimages map [uint64 ][]byte
31
+ type TestLogOptions struct {
32
+ Preimages map [uint64 ][]byte
33
+ ContinueExisting bool // if true, don'
34
+ SealKey * ecdsa.PrivateKey
35
+ UsingV0Seals bool
31
36
}
32
37
33
- type TestCreateLogOption func (* TestLogCreatorContext )
38
+ type TestLogOption func (* TestLogOptions )
34
39
35
- func TestWithCreateLogPreImages () TestCreateLogOption {
36
- return func (c * TestLogCreatorContext ) {
40
+ func TestWithCreateLogPreImages () TestLogOption {
41
+ return func (c * TestLogOptions ) {
37
42
c .Preimages = make (map [uint64 ][]byte )
38
43
}
39
44
}
40
45
46
+ func TestWithSealKey (key * ecdsa.PrivateKey ) TestLogOption {
47
+ return func (c * TestLogOptions ) {
48
+ c .SealKey = key
49
+ }
50
+ }
51
+
52
+ func TestWithV0Seals () TestLogOption {
53
+ return func (c * TestLogOptions ) {
54
+ c .UsingV0Seals = true
55
+ }
56
+ }
57
+
41
58
// CreateLog creates a log with the given tenant identity, massif height, and mmr size,
42
59
// any previous seal or massif blobs for the same tenant are first deleted
60
+ // To create a single incomplete massif, call AddLeavesToLog with a leafCount instead of CreateLog
43
61
func (c * TestLocalReaderContext ) CreateLog (
44
62
tenantIdentity string , massifHeight uint8 , massifCount uint32 ,
45
- opts ... TestCreateLogOption ) {
63
+ opts ... TestLogOption ) {
46
64
47
- logContext := & TestLogCreatorContext {}
65
+ options := & TestLogOptions {}
48
66
for _ , opt := range opts {
49
- opt (logContext )
67
+ opt (options )
50
68
}
51
69
52
70
generator := MMRTestingGenerateNumberedLeaf
53
71
54
72
// If the caller needs to work with the pre-images we wrap the generator to retain them
55
- if logContext .Preimages != nil {
73
+ if options .Preimages != nil {
56
74
generator = func (tenantIdentity string , base , i uint64 ) mmrtesting.AddLeafArgs {
57
75
58
76
args := generator (tenantIdentity , base , i )
59
- logContext .Preimages [base + i ] = args .Value
77
+ options .Preimages [base + i ] = args .Value
60
78
return args
61
79
}
62
80
}
@@ -68,24 +86,47 @@ func (c *TestLocalReaderContext) CreateLog(
68
86
CommitmentEpoch : 1 ,
69
87
MassifHeight : massifHeight ,
70
88
SealOnCommit : true , // create seals for each massif as we go
89
+ SealerKey : options .SealKey ,
90
+ UseV0Seals : options .UsingV0Seals ,
71
91
}, c .AzuriteContext , c .G , generator )
72
92
require .NoError (c .AzuriteContext .T , err )
73
93
74
94
leavesPerMassif := mmr .HeightIndexLeafCount (uint64 (massifHeight ) - 1 )
75
95
96
+ // using base = 0 means the caller can't predict the leaf hash based on the mmr index, but otherwise it's fine
97
+ // if the caller is overriding the generator, they can do what they like
76
98
err = committer .AddLeaves (context .TODO (), tenantIdentity , 0 , leavesPerMassif * uint64 (massifCount ))
77
99
require .NoError (c .AzuriteContext .T , err )
78
100
}
79
101
80
102
// AddLeavesToLog adds the requested number of leaves to the log for the given
81
103
// tenant identity. Note the massifHeight must be the same as was provided to
82
104
// the corresponding CreateLog call
83
- func (c * TestLocalReaderContext ) AddLeavesToLog (tenantIdentity string , massifHeight uint8 , leafCount int ) {
105
+ // To create a single incomplete massif, call AddLeavesToLog with a leafCount instead of CreateLog
106
+ func (c * TestLocalReaderContext ) AddLeavesToLog (tenantIdentity string , massifHeight uint8 , leafCount int , opts ... TestLogOption ) {
107
+
108
+ options := & TestLogOptions {}
109
+ for _ , opt := range opts {
110
+ opt (options )
111
+ }
112
+ generator := MMRTestingGenerateNumberedLeaf
113
+
114
+ // If the caller needs to work with the pre-images we wrap the generator to retain them
115
+ if options .Preimages != nil {
116
+ generator = func (tenantIdentity string , base , i uint64 ) mmrtesting.AddLeafArgs {
117
+
118
+ args := generator (tenantIdentity , base , i )
119
+ options .Preimages [base + i ] = args .Value
120
+ return args
121
+ }
122
+ }
84
123
85
124
committer , err := NewTestMinimalCommitter (TestCommitterConfig {
86
125
CommitmentEpoch : 1 ,
87
126
MassifHeight : massifHeight ,
88
127
SealOnCommit : true , // create seals for each massif as we go
128
+ SealerKey : options .SealKey ,
129
+ UseV0Seals : options .UsingV0Seals ,
89
130
}, c .AzuriteContext , c .G , MMRTestingGenerateNumberedLeaf )
90
131
require .NoError (c .AzuriteContext .T , err )
91
132
0 commit comments