1
|
|
using System;
|
2
|
|
using System.Collections.Generic;
|
3
|
|
using System.Collections.Immutable;
|
4
|
|
using System.Security.Cryptography;
|
5
|
|
using Libplanet.Action;
|
6
|
|
using Libplanet.Blocks;
|
7
|
|
using Libplanet.Crypto;
|
8
|
|
using Libplanet.Store;
|
9
|
|
using Libplanet.Tests.Common.Action;
|
10
|
|
using Libplanet.Tx;
|
11
|
|
|
12
|
|
namespace Libplanet.Tests.Store
|
13
|
|
{
|
14
|
|
public abstract class StoreFixture : IDisposable
|
15
|
|
{
|
16
|
2
|
public StoreFixture(IAction blockAction = null)
|
17
|
2
|
{
|
18
|
2
|
StoreChainId = Guid.NewGuid();
|
19
|
|
|
20
|
2
|
Address1 = new Address(new byte[]
|
21
|
2
|
{
|
22
|
2
|
0x45, 0xa2, 0x21, 0x87, 0xe2, 0xd8, 0x85, 0x0b, 0xb3, 0x57,
|
23
|
2
|
0x88, 0x69, 0x58, 0xbc, 0x3e, 0x85, 0x60, 0x92, 0x9c, 0xcc,
|
24
|
2
|
});
|
25
|
2
|
Address2 = new Address(new byte[]
|
26
|
2
|
{
|
27
|
2
|
0x55, 0xa2, 0x21, 0x87, 0xe2, 0xd8, 0x85, 0x0b, 0xb3, 0x57,
|
28
|
2
|
0x88, 0x69, 0x58, 0xbc, 0x3e, 0x85, 0x60, 0x92, 0x9c, 0xdd,
|
29
|
2
|
});
|
30
|
2
|
Address3 = new Address(new byte[]
|
31
|
2
|
{
|
32
|
2
|
0xa3, 0x4b, 0x0c, 0x91, 0xda, 0x58, 0xd4, 0x73, 0xd3, 0x70,
|
33
|
2
|
0xc4, 0x5b, 0xf9, 0x6f, 0x6d, 0x98, 0xa5, 0x01, 0xd9, 0x22,
|
34
|
2
|
});
|
35
|
2
|
Address4 = new Address(new byte[]
|
36
|
2
|
{
|
37
|
2
|
0xbf, 0x78, 0x67, 0x29, 0xba, 0x04, 0x1b, 0xa7, 0x6f, 0xfb,
|
38
|
2
|
0xa0, 0x6c, 0x8c, 0x4d, 0xc1, 0x24, 0xee, 0x3e, 0x8c, 0x8b,
|
39
|
2
|
});
|
40
|
2
|
Address5 = new Address(new byte[]
|
41
|
2
|
{
|
42
|
2
|
0x03, 0xf0, 0x42, 0x7f, 0x2e, 0x6c, 0x0f, 0x5f, 0xdb, 0xd3,
|
43
|
2
|
0x77, 0x9d, 0xb2, 0x84, 0xd6, 0x1b, 0x04, 0x38, 0xdf, 0xb6,
|
44
|
2
|
});
|
45
|
2
|
TxId1 = new TxId(new byte[]
|
46
|
2
|
{
|
47
|
2
|
0x45, 0xa2, 0x21, 0x87, 0xe2, 0xd8, 0x85, 0x0b, 0xb3, 0x57,
|
48
|
2
|
0x88, 0x69, 0x58, 0xbc, 0x3e, 0x85, 0x60, 0x92, 0x9c, 0xcc,
|
49
|
2
|
0x88, 0x69, 0x58, 0xbc, 0x3e, 0x85, 0x60, 0x92, 0x9c, 0xcc,
|
50
|
2
|
0x9c, 0xcc,
|
51
|
2
|
});
|
52
|
2
|
TxId2 = new TxId(new byte[]
|
53
|
2
|
{
|
54
|
2
|
0x45, 0xa2, 0x21, 0x87, 0xe2, 0xd8, 0x85, 0x0b, 0xb3, 0x57,
|
55
|
2
|
0x88, 0x69, 0x58, 0xbc, 0x3e, 0x85, 0x60, 0x92, 0x9c, 0xcc,
|
56
|
2
|
0x88, 0x69, 0x58, 0xbc, 0x3e, 0x85, 0x60, 0x92, 0x9c, 0xcc,
|
57
|
2
|
0x9c, 0xdd,
|
58
|
2
|
});
|
59
|
2
|
TxId3 = new TxId(new byte[]
|
60
|
2
|
{
|
61
|
2
|
0x45, 0xa2, 0x21, 0x87, 0xe2, 0xd8, 0x85, 0x0b, 0xb3, 0x57,
|
62
|
2
|
0x88, 0x69, 0x58, 0xbc, 0x3e, 0x85, 0x60, 0x92, 0x9c, 0xcc,
|
63
|
2
|
0x88, 0x69, 0x58, 0xbc, 0x3e, 0x85, 0x60, 0x92, 0x9c, 0xcc,
|
64
|
2
|
0x9c, 0xee,
|
65
|
2
|
});
|
66
|
2
|
Hash1 = new HashDigest<SHA256>(new byte[]
|
67
|
2
|
{
|
68
|
2
|
0x45, 0xa2, 0x21, 0x87, 0xe2, 0xd8, 0x85, 0x0b, 0xb3, 0x57,
|
69
|
2
|
0x88, 0x69, 0x58, 0xbc, 0x3e, 0x85, 0x60, 0x92, 0x9c, 0xcc,
|
70
|
2
|
0x88, 0x69, 0x58, 0xbc, 0x3e, 0x85, 0x60, 0x92, 0x9c, 0xcc,
|
71
|
2
|
0x9c, 0xcc,
|
72
|
2
|
});
|
73
|
2
|
Hash2 = new HashDigest<SHA256>(new byte[]
|
74
|
2
|
{
|
75
|
2
|
0x45, 0xa2, 0x21, 0x87, 0xe2, 0xd8, 0x85, 0x0b, 0xb3, 0x57,
|
76
|
2
|
0x88, 0x69, 0x58, 0xbc, 0x3e, 0x85, 0x60, 0x92, 0x9c, 0xcc,
|
77
|
2
|
0x88, 0x69, 0x58, 0xbc, 0x3e, 0x85, 0x60, 0x92, 0x9c, 0xcc,
|
78
|
2
|
0x9c, 0xdd,
|
79
|
2
|
});
|
80
|
2
|
Hash3 = new HashDigest<SHA256>(new byte[]
|
81
|
2
|
{
|
82
|
2
|
0x45, 0xa2, 0x21, 0x87, 0xe2, 0xd8, 0x85, 0x0b, 0xb3, 0x57,
|
83
|
2
|
0x88, 0x69, 0x58, 0xbc, 0x3e, 0x85, 0x60, 0x92, 0x9c, 0xcc,
|
84
|
2
|
0x88, 0x69, 0x58, 0xbc, 0x3e, 0x85, 0x60, 0x92, 0x9c, 0xcc,
|
85
|
2
|
0x9c, 0xee,
|
86
|
2
|
});
|
87
|
|
|
88
|
2
|
GenesisBlock = TestUtils.MineGenesis<DumbAction>(blockAction: blockAction);
|
89
|
2
|
Block1 = TestUtils.MineNext(GenesisBlock);
|
90
|
2
|
Block2 = TestUtils.MineNext(Block1);
|
91
|
2
|
Block3 = TestUtils.MineNext(Block2);
|
92
|
|
|
93
|
2
|
Transaction1 = MakeTransaction(new List<DumbAction>(), ImmutableHashSet<Address>.Empty);
|
94
|
2
|
Transaction2 = MakeTransaction(new List<DumbAction>(), ImmutableHashSet<Address>.Empty);
|
95
|
2
|
Transaction3 = MakeTransaction(new List<DumbAction>(), ImmutableHashSet<Address>.Empty);
|
96
|
2
|
}
|
97
|
|
|
98
|
2
|
public Guid StoreChainId { get; }
|
99
|
|
|
100
|
2
|
public Address Address1 { get; }
|
101
|
|
|
102
|
2
|
public Address Address2 { get; }
|
103
|
|
|
104
|
2
|
public Address Address3 { get; }
|
105
|
|
|
106
|
1
|
public Address Address4 { get; }
|
107
|
|
|
108
|
1
|
public Address Address5 { get; }
|
109
|
|
|
110
|
0
|
public TxId TxId1 { get; }
|
111
|
|
|
112
|
0
|
public TxId TxId2 { get; }
|
113
|
|
|
114
|
0
|
public TxId TxId3 { get; }
|
115
|
|
|
116
|
2
|
public HashDigest<SHA256> Hash1 { get; }
|
117
|
|
|
118
|
2
|
public HashDigest<SHA256> Hash2 { get; }
|
119
|
|
|
120
|
2
|
public HashDigest<SHA256> Hash3 { get; }
|
121
|
|
|
122
|
2
|
public Block<DumbAction> GenesisBlock { get; }
|
123
|
|
|
124
|
2
|
public Block<DumbAction> Block1 { get; }
|
125
|
|
|
126
|
2
|
public Block<DumbAction> Block2 { get; }
|
127
|
|
|
128
|
2
|
public Block<DumbAction> Block3 { get; }
|
129
|
|
|
130
|
2
|
public Transaction<DumbAction> Transaction1 { get; }
|
131
|
|
|
132
|
2
|
public Transaction<DumbAction> Transaction2 { get; }
|
133
|
|
|
134
|
2
|
public Transaction<DumbAction> Transaction3 { get; }
|
135
|
|
|
136
|
2
|
public IStore Store { get; set; }
|
137
|
|
|
138
|
2
|
public IStateStore StateStore { get; set; }
|
139
|
|
|
140
|
2
|
public IBlockStatesStore BlockStatesStore => StateStore as IBlockStatesStore;
|
141
|
|
|
142
|
|
public abstract void Dispose();
|
143
|
|
|
144
|
|
public Transaction<DumbAction> MakeTransaction(
|
145
|
|
IEnumerable<DumbAction> actions = null,
|
146
|
|
ImmutableHashSet<Address> updatedAddresses = null,
|
147
|
|
long nonce = 0,
|
148
|
|
PrivateKey privateKey = null,
|
149
|
|
DateTimeOffset? timestamp = null
|
150
|
|
)
|
151
|
2
|
{
|
152
|
2
|
privateKey = privateKey ?? new PrivateKey();
|
153
|
2
|
timestamp = timestamp ??
|
154
|
2
|
new DateTimeOffset(2018, 11, 21, 0, 0, 0, TimeSpan.Zero);
|
155
|
2
|
return Transaction<DumbAction>.Create(
|
156
|
2
|
nonce,
|
157
|
2
|
privateKey,
|
158
|
2
|
GenesisBlock.Hash,
|
159
|
2
|
actions ?? new DumbAction[0],
|
160
|
2
|
updatedAddresses,
|
161
|
2
|
timestamp
|
162
|
2
|
);
|
163
|
2
|
}
|
164
|
|
}
|
165
|
|
}
|