Skip to content

Commit 3cac393

Browse files
Alexey-N-ChernyshovWarchant
authored andcommitted
Tests for 1.1.0 (#48)
* Update to Iroha 1.1.0 Signed-off-by: Alexey Chernyshov <[email protected]> * Add tests for QueryAPI Signed-off-by: Alexey Chernyshov <[email protected]>
1 parent ca50127 commit 3cac393

File tree

3 files changed

+125
-21
lines changed

3 files changed

+125
-21
lines changed

client/src/main/java/jp/co/soramitsu/iroha/java/QueryAPI.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package jp.co.soramitsu.iroha.java;
22

33
import iroha.protocol.QryResponses.AccountAssetResponse;
4+
import iroha.protocol.QryResponses.AccountDetailResponse;
45
import iroha.protocol.QryResponses.AccountResponse;
56
import iroha.protocol.QryResponses.AssetResponse;
67
import iroha.protocol.QryResponses.BlockResponse;
@@ -86,7 +87,7 @@ public String getAccountDetails(
8687
return adr.getDetail();
8788
}
8889

89-
public String getAccountDetails(
90+
public AccountDetailResponse getAccountDetails(
9091
String accountId,
9192
String writer,
9293
String key,
@@ -109,12 +110,10 @@ public String getAccountDetails(
109110

110111
checkErrorResponse(res);
111112

112-
val adr = res.getAccountDetailResponse();
113-
114-
return adr.getDetail();
113+
return res.getAccountDetailResponse();
115114
}
116115

117-
public String getAccountDetails(
116+
public AccountDetailResponse getAccountDetails(
118117
String accountId,
119118
String writer,
120119
String key,
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package jp.co.soramitsu.iroha.java
2+
3+
import jp.co.soramitsu.iroha.java.debug.Account
4+
import jp.co.soramitsu.iroha.testcontainers.IrohaContainer
5+
import jp.co.soramitsu.iroha.testcontainers.PeerConfig
6+
import jp.co.soramitsu.iroha.testcontainers.detail.GenesisBlockBuilder
7+
import spock.lang.Specification
8+
import spock.lang.Unroll
9+
10+
import static jp.co.soramitsu.iroha.java.Transaction.builder
11+
import static jp.co.soramitsu.iroha.testcontainers.detail.GenesisBlockBuilder.defaultAccountId
12+
import static jp.co.soramitsu.iroha.testcontainers.detail.GenesisBlockBuilder.defaultKeyPair
13+
14+
class CommandsTest extends Specification {
15+
16+
static Account account = Account.create("a@test")
17+
18+
static IrohaAPI api
19+
static def iroha = new IrohaContainer()
20+
.withPeerConfig(
21+
PeerConfig.builder()
22+
.genesisBlock(getGenesisBlock())
23+
.build())
24+
25+
def setupSpec() {
26+
iroha.start()
27+
api = iroha.getApi()
28+
}
29+
30+
def cleanupSpec() {
31+
iroha.stop()
32+
}
33+
34+
static def setDetail(Account account, String key, String value) {
35+
return builder(account.id)
36+
.setAccountDetail(account.id, key, value)
37+
.sign(account.keyPair)
38+
.build()
39+
}
40+
41+
static def createAccount(Account a) {
42+
return Transaction.builder(defaultAccountId)
43+
.createAccount(a.id, a.keyPair.public)
44+
.sign(defaultKeyPair)
45+
.build()
46+
}
47+
48+
static def getGenesisBlock() {
49+
return new GenesisBlockBuilder()
50+
.addDefaultTransaction()
51+
.addTransaction(createAccount(account))
52+
.addTransaction(setDetail(account, "initial_key1", "initial_val"))
53+
.addTransaction(setDetail(account, "initial_key2", "initial_val"))
54+
.build()
55+
}
56+
57+
@Unroll
58+
def "compareAndSet command: key=#key, value=#value, oldValue=#oldValue"() {
59+
given:
60+
def qapi = new QueryAPI(api, account)
61+
62+
when:
63+
def tx = Transaction.builder(account.getId())
64+
.compareAndSetAccountDetail(account.getId(), key, value, oldValue)
65+
.sign(account.keyPair)
66+
.build()
67+
api.transaction(tx).blockingSubscribe()
68+
69+
def actual_value = qapi.getAccountDetails(account.getId(), account.getId(), key, 1).getDetail()
70+
71+
then:
72+
actual_value == expected_value
73+
74+
where:
75+
key | value | oldValue | expected_value
76+
"initial_key1" | "updated_val" | "wrong_val" | "{ \"a@test\" : { \"initial_key1\" : \"initial_val\" } }"
77+
"initial_key1" | "updated_val" | null | "{ \"a@test\" : { \"initial_key1\" : \"initial_val\" } }"
78+
"initial_key2" | "updated_val" | "initial_val" | "{ \"a@test\" : { \"initial_key2\" : \"updated_val\" } }"
79+
// Seems to be failed in Iroha
80+
//"empty1" | "value" | "wrong" | "{}"
81+
"empty2" | "value" | null | "{ \"a@test\" : { \"empty2\" : \"value\" } }"
82+
}
83+
}

client/src/test/groovy/jp/co/soramitsu/iroha/java/QueryApiTest.groovy

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ class QueryApiTest extends Specification {
1919
static IrohaAPI api
2020
static def iroha = new IrohaContainer()
2121
.withPeerConfig(
22-
PeerConfig.builder()
23-
.genesisBlock(getGenesisBlock())
24-
.build())
22+
PeerConfig.builder()
23+
.genesisBlock(getGenesisBlock())
24+
.build())
2525

2626
def setupSpec() {
2727
iroha.start()
@@ -74,9 +74,9 @@ class QueryApiTest extends Specification {
7474
def response = qapi.getPeers()
7575

7676
then:
77-
(response.getPeersCount() == 1) &&
78-
(response.getPeers(0).getAddress() == expected_address) &&
79-
(response.getPeers(0).getPeerKey() == expected_key)
77+
response.getPeersCount() == 1
78+
response.getPeers(0).getAddress() == expected_address
79+
response.getPeers(0).getPeerKey() == expected_key
8080

8181
where:
8282
issuer | expected_address | expected_key
@@ -89,7 +89,7 @@ class QueryApiTest extends Specification {
8989
def qapi = new QueryAPI(api, issuer)
9090

9191
when:
92-
def actual_value = qapi.getAccountDetails(accountId, writer, key)
92+
def actual_value = qapi.getAccountDetails(accountId, writer, key, 10).getDetail()
9393

9494
then:
9595
actual_value == expected_value
@@ -109,20 +109,42 @@ class QueryApiTest extends Specification {
109109
A | B.id | A.id | "key2" | "{}"
110110
}
111111

112+
@Unroll
113+
def "getAccountDetail pagination test: accountId=#accountId, writer=#writer, key=#key, nextWriter=#nextWriter, nextKet=#nextKey"() {
114+
given:
115+
def qapi = new QueryAPI(api, A)
116+
117+
when:
118+
def res = qapi.getAccountDetails(accountId, writer, key, 1, nextWriter, nextKey)
119+
def actualValue = res.getDetail()
120+
def actualNextWriter = res.getNextRecordId().writer
121+
def actualNextKey = res.getNextRecordId().key
122+
123+
then:
124+
actualValue == expectedValue
125+
actualNextWriter == expectedNextWriter
126+
actualNextKey == expectedNextKey
127+
128+
where:
129+
accountId | writer | key | nextWriter | nextKey | expectedValue | expectedNextWriter | expectedNextKey
130+
null | null | null | null | null | "{ \"a@test\" : { \"key1\" : \"Avalue1\" } }" | "a@test" | "key2"
131+
null | null | null | "a@test" | "key2" | "{ \"a@test\" : { \"key2\" : \"Avalue3\" } }" | "a@test" | "key4"
132+
}
133+
112134
@Unroll
113135
def "exception in @Deprecated getAccountDetails"(Account issuer, String accountId, String writer, String key) {
114136
given:
115137
def qapi = new QueryAPI(api, issuer)
116138

117139
when:
118-
qapi.getAccountDetails(accountId, writer, key)
140+
qapi.getAccountDetails(accountId, writer, key, 1)
119141

120142
then:
121143
thrown ErrorResponseException
122144

123145
where:
124-
issuer | accountId | writer | key
125-
A | "nonexistent@domain" | null | null
146+
issuer | accountId | writer | key
147+
A | "nonexistent@domain" | null | null
126148
}
127149

128150
def "validation exception in getAccountDetails"(Account issuer, String accountId, String writer, String key, Integer pageSize) {
@@ -136,10 +158,10 @@ class QueryApiTest extends Specification {
136158
thrown ValidationException
137159

138160
where:
139-
issuer | accountId | writer | key | pageSize
140-
A | "invalid" | null | null | 10
141-
A | null | null | null | -10
142-
A | null | null | null | 0
161+
issuer | accountId | writer | key | pageSize
162+
A | "invalid" | null | null | 10
163+
A | null | null | null | -10
164+
A | null | null | null | 0
143165
}
144166

145167
def "exception in getAccountDetails"(Account issuer, String accountId, String writer, String key, Integer pageSize) {
@@ -153,8 +175,8 @@ class QueryApiTest extends Specification {
153175
thrown ErrorResponseException
154176

155177
where:
156-
issuer | accountId | writer | key | pageSize
157-
A | "nonexistent@domain" | null | null | 10
178+
issuer | accountId | writer | key | pageSize
179+
A | "nonexistent@domain" | null | null | 10
158180
}
159181

160182
@Unroll

0 commit comments

Comments
 (0)