Skip to content

Commit 422e56c

Browse files
authored
Merge pull request #926 from input-output-hk/ETCM-468-complement-tests
ETCM-468-complement get proof service tests
2 parents 86053a0 + 93333bb commit 422e56c

File tree

1 file changed

+77
-11
lines changed

1 file changed

+77
-11
lines changed

src/test/scala/io/iohk/ethereum/jsonrpc/EthProofServiceSpec.scala

Lines changed: 77 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import org.scalatest.concurrent.ScalaFutures
2727
import org.scalatest.flatspec.AnyFlatSpecLike
2828
import org.scalatest.matchers.should.Matchers
2929
import io.iohk.ethereum.mpt.MerklePatriciaTrie.defaultByteArraySerializable
30+
import io.iohk.ethereum.rlp.RLPValue
3031

3132
class EthProofServiceSpec
3233
extends TestKit(ActorSystem("EthGetProofSpec_ActorSystem"))
@@ -95,11 +96,22 @@ class EthProofServiceSpec
9596
result.isRight shouldBe true
9697
result.fold(
9798
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 => {
100111
v.proof.nonEmpty shouldBe true
101112
v.value shouldBe BigInt(0)
102113
})
114+
}
103115
)
104116
}
105117

@@ -109,11 +121,22 @@ class EthProofServiceSpec
109121
result.isRight shouldBe true
110122
result.fold(
111123
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
113135
r.proofAccount.storageProof.map(v => {
114136
v.proof.nonEmpty shouldBe true
115137
v.value shouldBe BigInt(value)
116138
})
139+
}
117140
)
118141
}
119142

@@ -125,8 +148,18 @@ class EthProofServiceSpec
125148
result.fold(
126149
l => l,
127150
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 => {
130163
v.proof.nonEmpty shouldBe true
131164
expectedValueStorageKey should contain(v.value)
132165
})
@@ -143,8 +176,39 @@ class EthProofServiceSpec
143176
result.fold(
144177
l => l,
145178
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
148212
}
149213
)
150214
}
@@ -153,6 +217,8 @@ class EthProofServiceSpec
153217

154218
val blockGenerator = mock[EthashBlockGenerator]
155219
val address = Address(ByteString(Hex.decode("abbb6bebfa05aa13e908eaa492bd7a8343760477")))
220+
val balance = UInt256(0)
221+
val nonce = 0
156222

157223
val key = 333
158224
val value = 123
@@ -171,8 +237,8 @@ class EthProofServiceSpec
171237
.put(UInt256(key2), UInt256(value2))
172238

173239
val account = Account(
174-
nonce = 0,
175-
balance = UInt256(0),
240+
nonce = nonce,
241+
balance = balance,
176242
storageRoot = ByteString(storageMpt.getRootHash)
177243
)
178244

@@ -202,8 +268,8 @@ class EthProofServiceSpec
202268
blockNumber: BlockParam
203269
): ServiceResponse[ProofService.GetProofResponse] = {
204270
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
207273
}
208274

209275
val ethUserService = new EthUserService(

0 commit comments

Comments
 (0)