@@ -27,6 +27,7 @@ import org.scalatest.concurrent.ScalaFutures
27
27
import org .scalatest .flatspec .AnyFlatSpecLike
28
28
import org .scalatest .matchers .should .Matchers
29
29
import io .iohk .ethereum .mpt .MerklePatriciaTrie .defaultByteArraySerializable
30
+ import io .iohk .ethereum .rlp .RLPValue
30
31
31
32
class EthProofServiceSpec
32
33
extends TestKit (ActorSystem (" EthGetProofSpec_ActorSystem" ))
@@ -95,11 +96,22 @@ class EthProofServiceSpec
95
96
result.isRight shouldBe true
96
97
result.fold(
97
98
l => l,
98
- r =>
99
- r.proofAccount.storageProof.map(v => {
99
+ r => {
100
+ val accountProof = r.proofAccount
101
+ accountProof.address should matchTo(address)
102
+ accountProof.accountProof.foreach { p =>
103
+ p should not be empty
104
+ }
105
+ accountProof.accountProof.head shouldBe rlp.encode(RLPValue (mpt.getRootHash))
106
+ accountProof.balance shouldBe balance.toBigInt
107
+ accountProof.codeHash shouldBe account.codeHash
108
+ accountProof.nonce shouldBe nonce
109
+ accountProof.storageHash shouldBe account.storageRoot
110
+ accountProof.storageProof.map(v => {
100
111
v.proof.nonEmpty shouldBe true
101
112
v.value shouldBe BigInt (0 )
102
113
})
114
+ }
103
115
)
104
116
}
105
117
@@ -109,11 +121,22 @@ class EthProofServiceSpec
109
121
result.isRight shouldBe true
110
122
result.fold(
111
123
l => l,
112
- r =>
124
+ r => {
125
+ val accountProof = r.proofAccount
126
+ accountProof.address should matchTo(address)
127
+ accountProof.accountProof.foreach { p =>
128
+ p should not be empty
129
+ }
130
+ accountProof.accountProof.head shouldBe rlp.encode(RLPValue (mpt.getRootHash))
131
+ accountProof.balance shouldBe balance.toBigInt
132
+ accountProof.codeHash shouldBe account.codeHash
133
+ accountProof.nonce shouldBe nonce
134
+ accountProof.storageHash shouldBe account.storageRoot
113
135
r.proofAccount.storageProof.map(v => {
114
136
v.proof.nonEmpty shouldBe true
115
137
v.value shouldBe BigInt (value)
116
138
})
139
+ }
117
140
)
118
141
}
119
142
@@ -125,8 +148,18 @@ class EthProofServiceSpec
125
148
result.fold(
126
149
l => l,
127
150
r => {
128
- r.proofAccount.storageProof.size shouldBe 2
129
- r.proofAccount.storageProof.map(v => {
151
+ val accountProof = r.proofAccount
152
+ accountProof.address should matchTo(address)
153
+ accountProof.accountProof.foreach { p =>
154
+ p should not be empty
155
+ }
156
+ accountProof.accountProof.head shouldBe rlp.encode(RLPValue (mpt.getRootHash))
157
+ accountProof.balance shouldBe balance.toBigInt
158
+ accountProof.codeHash shouldBe account.codeHash
159
+ accountProof.nonce shouldBe nonce
160
+ accountProof.storageHash shouldBe account.storageRoot
161
+ accountProof.storageProof.size shouldBe 2
162
+ accountProof.storageProof.map(v => {
130
163
v.proof.nonEmpty shouldBe true
131
164
expectedValueStorageKey should contain(v.value)
132
165
})
@@ -143,8 +176,39 @@ class EthProofServiceSpec
143
176
result.fold(
144
177
l => l,
145
178
r => {
146
- r.proofAccount.storageProof.size shouldBe 3
147
- expectedValueStorageKey.forall(r.proofAccount.storageProof.map(_.value).contains) shouldBe true
179
+ val accountProof = r.proofAccount
180
+ accountProof.address should matchTo(address)
181
+ accountProof.accountProof.foreach { p =>
182
+ p should not be empty
183
+ }
184
+ accountProof.accountProof.head shouldBe rlp.encode(RLPValue (mpt.getRootHash))
185
+ accountProof.balance shouldBe balance.toBigInt
186
+ accountProof.codeHash shouldBe account.codeHash
187
+ accountProof.nonce shouldBe nonce
188
+ accountProof.storageHash shouldBe account.storageRoot
189
+ accountProof.storageProof.size shouldBe 3
190
+ expectedValueStorageKey.forall(accountProof.storageProof.map(_.value).contains) shouldBe true
191
+ }
192
+ )
193
+ }
194
+
195
+ " EthProofService" should " return account proof and account details, with empty storage proof" in new TestSetup {
196
+ val result = fetchProof(address, Seq .empty, blockNumber).runSyncUnsafe()
197
+ result.isRight shouldBe true
198
+ result.fold(
199
+ l => l,
200
+ r => {
201
+ val accountProof = r.proofAccount
202
+ accountProof.address should matchTo(address)
203
+ accountProof.accountProof.foreach { p =>
204
+ p should not be empty
205
+ }
206
+ accountProof.accountProof.head shouldBe rlp.encode(RLPValue (mpt.getRootHash))
207
+ accountProof.balance shouldBe balance.toBigInt
208
+ accountProof.codeHash shouldBe account.codeHash
209
+ accountProof.nonce shouldBe nonce
210
+ accountProof.storageHash shouldBe account.storageRoot
211
+ accountProof.storageProof.size shouldBe 0
148
212
}
149
213
)
150
214
}
@@ -153,6 +217,8 @@ class EthProofServiceSpec
153
217
154
218
val blockGenerator = mock[EthashBlockGenerator ]
155
219
val address = Address (ByteString (Hex .decode(" abbb6bebfa05aa13e908eaa492bd7a8343760477" )))
220
+ val balance = UInt256 (0 )
221
+ val nonce = 0
156
222
157
223
val key = 333
158
224
val value = 123
@@ -171,8 +237,8 @@ class EthProofServiceSpec
171
237
.put(UInt256 (key2), UInt256 (value2))
172
238
173
239
val account = Account (
174
- nonce = 0 ,
175
- balance = UInt256 ( 0 ) ,
240
+ nonce = nonce ,
241
+ balance = balance ,
176
242
storageRoot = ByteString (storageMpt.getRootHash)
177
243
)
178
244
@@ -202,8 +268,8 @@ class EthProofServiceSpec
202
268
blockNumber : BlockParam
203
269
): ServiceResponse [ProofService .GetProofResponse ] = {
204
270
val request = GetProofRequest (address, storageKeys, blockNumber)
205
- val retrievedAccountProofWrong : ServiceResponse [ProofService .GetProofResponse ] = ethGetProof.getProof(request)
206
- retrievedAccountProofWrong
271
+ val retrievedAccountProof : ServiceResponse [ProofService .GetProofResponse ] = ethGetProof.getProof(request)
272
+ retrievedAccountProof
207
273
}
208
274
209
275
val ethUserService = new EthUserService (
0 commit comments