Skip to content

Commit 60c28af

Browse files
committed
[ETCM-533] refactoring EthProofServiceSpec
1 parent 3664a49 commit 60c28af

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

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

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,14 @@ class EthProofServiceSpec
7979

8080
"EthProofService" should "return an error when the proof is requested for non-existing account" in new TestSetup {
8181
val wrongAddress = Address(666)
82-
val request = GetProofRequest(wrongAddress, storageKeys, blockNumber)
83-
val retrievedAccountProofWrong: ServiceResponse[ProofService.GetProofResponse] = ethGetProof.getProof(request)
84-
val result = retrievedAccountProofWrong.runSyncUnsafe()
85-
82+
val result = fetchProof(wrongAddress, storageKeys, blockNumber).runSyncUnsafe()
8683
result.isLeft shouldBe true
8784
result.fold(l => l.message should include("No account found for Address"), r => r)
8885
}
8986

9087
"EthProofService" should "return the proof with empty value for non-existing storage key" in new TestSetup {
9188
val wrongStorageKey = Seq(StorageProofKey(321))
92-
val request = GetProofRequest(address, wrongStorageKey, blockNumber)
93-
val retrievedAccountProofWrong: ServiceResponse[ProofService.GetProofResponse] = ethGetProof.getProof(request)
94-
val result = retrievedAccountProofWrong.runSyncUnsafe()
89+
val result = fetchProof(address, wrongStorageKey, blockNumber).runSyncUnsafe()
9590
result.isRight shouldBe true
9691
result.fold(l => l, r => r.proofAccount.storageProof.map(v => {
9792
v.proof.nonEmpty shouldBe true
@@ -101,9 +96,7 @@ class EthProofServiceSpec
10196

10297
"EthProofService" should "return the proof and value for existing storage key" in new TestSetup {
10398
val storageKey = Seq(StorageProofKey(key))
104-
val request = GetProofRequest(address, storageKey, blockNumber)
105-
val retrievedAccountProofWrong: ServiceResponse[ProofService.GetProofResponse] = ethGetProof.getProof(request)
106-
val result = retrievedAccountProofWrong.runSyncUnsafe()
99+
val result = fetchProof(address, storageKey, blockNumber).runSyncUnsafe()
107100
result.isRight shouldBe true
108101
result.fold(l => l, r => r.proofAccount.storageProof.map(v => {
109102
v.proof.nonEmpty shouldBe true
@@ -114,9 +107,7 @@ class EthProofServiceSpec
114107
"EthProofService" should "return the proof and value for multiple existing storage keys" in new TestSetup {
115108
val storageKey = Seq(StorageProofKey(key), StorageProofKey(key2))
116109
val expectedValueStorageKey = Seq(BigInt(value), BigInt(value2))
117-
val request = GetProofRequest(address, storageKey, blockNumber)
118-
val retrievedAccountProofWrong: ServiceResponse[ProofService.GetProofResponse] = ethGetProof.getProof(request)
119-
val result = retrievedAccountProofWrong.runSyncUnsafe()
110+
val result = fetchProof(address, storageKey, blockNumber).runSyncUnsafe()
120111
result.isRight shouldBe true
121112
result.fold(l => l, r => {
122113
r.proofAccount.storageProof.size shouldBe 2
@@ -131,9 +122,7 @@ class EthProofServiceSpec
131122
val wrongStorageKey = StorageProofKey(321)
132123
val storageKey = Seq(StorageProofKey(key), StorageProofKey(key2)) :+ wrongStorageKey
133124
val expectedValueStorageKey = Seq(BigInt(value), BigInt(value2), BigInt(0))
134-
val request = GetProofRequest(address, storageKey, blockNumber)
135-
val retrievedAccountProofWrong: ServiceResponse[ProofService.GetProofResponse] = ethGetProof.getProof(request)
136-
val result = retrievedAccountProofWrong.runSyncUnsafe()
125+
val result = fetchProof(address, storageKey, blockNumber).runSyncUnsafe()
137126
result.isRight shouldBe true
138127
result.fold(l => l, r => {
139128
r.proofAccount.storageProof.size shouldBe 3
@@ -188,6 +177,12 @@ class EthProofServiceSpec
188177

189178
override lazy val ledger = mock[Ledger]
190179

180+
def fetchProof(address: Address, storageKeys: Seq[StorageProofKey], blockNumber: BlockParam): ServiceResponse[ProofService.GetProofResponse] = {
181+
val request = GetProofRequest(address, storageKeys, blockNumber)
182+
val retrievedAccountProofWrong: ServiceResponse[ProofService.GetProofResponse] = ethGetProof.getProof(request)
183+
retrievedAccountProofWrong
184+
}
185+
191186
val ethUserService = new EthUserService(
192187
blockchain,
193188
ledger,

0 commit comments

Comments
 (0)