Skip to content

Commit

Permalink
Tests for 1.1.0 (#48)
Browse files Browse the repository at this point in the history
* Update to Iroha 1.1.0

Signed-off-by: Alexey Chernyshov <alexey.n.chernyshov@gmail.com>

* Add tests for QueryAPI

Signed-off-by: Alexey Chernyshov <alexey.n.chernyshov@gmail.com>
  • Loading branch information
Alexey-N-Chernyshov authored and Warchant committed Jul 29, 2019
1 parent ca50127 commit 3cac393
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 21 deletions.
9 changes: 4 additions & 5 deletions client/src/main/java/jp/co/soramitsu/iroha/java/QueryAPI.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package jp.co.soramitsu.iroha.java;

import iroha.protocol.QryResponses.AccountAssetResponse;
import iroha.protocol.QryResponses.AccountDetailResponse;
import iroha.protocol.QryResponses.AccountResponse;
import iroha.protocol.QryResponses.AssetResponse;
import iroha.protocol.QryResponses.BlockResponse;
Expand Down Expand Up @@ -86,7 +87,7 @@ public String getAccountDetails(
return adr.getDetail();
}

public String getAccountDetails(
public AccountDetailResponse getAccountDetails(
String accountId,
String writer,
String key,
Expand All @@ -109,12 +110,10 @@ public String getAccountDetails(

checkErrorResponse(res);

val adr = res.getAccountDetailResponse();

return adr.getDetail();
return res.getAccountDetailResponse();
}

public String getAccountDetails(
public AccountDetailResponse getAccountDetails(
String accountId,
String writer,
String key,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package jp.co.soramitsu.iroha.java

import jp.co.soramitsu.iroha.java.debug.Account
import jp.co.soramitsu.iroha.testcontainers.IrohaContainer
import jp.co.soramitsu.iroha.testcontainers.PeerConfig
import jp.co.soramitsu.iroha.testcontainers.detail.GenesisBlockBuilder
import spock.lang.Specification
import spock.lang.Unroll

import static jp.co.soramitsu.iroha.java.Transaction.builder
import static jp.co.soramitsu.iroha.testcontainers.detail.GenesisBlockBuilder.defaultAccountId
import static jp.co.soramitsu.iroha.testcontainers.detail.GenesisBlockBuilder.defaultKeyPair

class CommandsTest extends Specification {

static Account account = Account.create("a@test")

static IrohaAPI api
static def iroha = new IrohaContainer()
.withPeerConfig(
PeerConfig.builder()
.genesisBlock(getGenesisBlock())
.build())

def setupSpec() {
iroha.start()
api = iroha.getApi()
}

def cleanupSpec() {
iroha.stop()
}

static def setDetail(Account account, String key, String value) {
return builder(account.id)
.setAccountDetail(account.id, key, value)
.sign(account.keyPair)
.build()
}

static def createAccount(Account a) {
return Transaction.builder(defaultAccountId)
.createAccount(a.id, a.keyPair.public)
.sign(defaultKeyPair)
.build()
}

static def getGenesisBlock() {
return new GenesisBlockBuilder()
.addDefaultTransaction()
.addTransaction(createAccount(account))
.addTransaction(setDetail(account, "initial_key1", "initial_val"))
.addTransaction(setDetail(account, "initial_key2", "initial_val"))
.build()
}

@Unroll
def "compareAndSet command: key=#key, value=#value, oldValue=#oldValue"() {
given:
def qapi = new QueryAPI(api, account)

when:
def tx = Transaction.builder(account.getId())
.compareAndSetAccountDetail(account.getId(), key, value, oldValue)
.sign(account.keyPair)
.build()
api.transaction(tx).blockingSubscribe()

def actual_value = qapi.getAccountDetails(account.getId(), account.getId(), key, 1).getDetail()

then:
actual_value == expected_value

where:
key | value | oldValue | expected_value
"initial_key1" | "updated_val" | "wrong_val" | "{ \"a@test\" : { \"initial_key1\" : \"initial_val\" } }"
"initial_key1" | "updated_val" | null | "{ \"a@test\" : { \"initial_key1\" : \"initial_val\" } }"
"initial_key2" | "updated_val" | "initial_val" | "{ \"a@test\" : { \"initial_key2\" : \"updated_val\" } }"
// Seems to be failed in Iroha
//"empty1" | "value" | "wrong" | "{}"
"empty2" | "value" | null | "{ \"a@test\" : { \"empty2\" : \"value\" } }"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class QueryApiTest extends Specification {
static IrohaAPI api
static def iroha = new IrohaContainer()
.withPeerConfig(
PeerConfig.builder()
.genesisBlock(getGenesisBlock())
.build())
PeerConfig.builder()
.genesisBlock(getGenesisBlock())
.build())

def setupSpec() {
iroha.start()
Expand Down Expand Up @@ -74,9 +74,9 @@ class QueryApiTest extends Specification {
def response = qapi.getPeers()

then:
(response.getPeersCount() == 1) &&
(response.getPeers(0).getAddress() == expected_address) &&
(response.getPeers(0).getPeerKey() == expected_key)
response.getPeersCount() == 1
response.getPeers(0).getAddress() == expected_address
response.getPeers(0).getPeerKey() == expected_key

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

when:
def actual_value = qapi.getAccountDetails(accountId, writer, key)
def actual_value = qapi.getAccountDetails(accountId, writer, key, 10).getDetail()

then:
actual_value == expected_value
Expand All @@ -109,20 +109,42 @@ class QueryApiTest extends Specification {
A | B.id | A.id | "key2" | "{}"
}

@Unroll
def "getAccountDetail pagination test: accountId=#accountId, writer=#writer, key=#key, nextWriter=#nextWriter, nextKet=#nextKey"() {
given:
def qapi = new QueryAPI(api, A)

when:
def res = qapi.getAccountDetails(accountId, writer, key, 1, nextWriter, nextKey)
def actualValue = res.getDetail()
def actualNextWriter = res.getNextRecordId().writer
def actualNextKey = res.getNextRecordId().key

then:
actualValue == expectedValue
actualNextWriter == expectedNextWriter
actualNextKey == expectedNextKey

where:
accountId | writer | key | nextWriter | nextKey | expectedValue | expectedNextWriter | expectedNextKey
null | null | null | null | null | "{ \"a@test\" : { \"key1\" : \"Avalue1\" } }" | "a@test" | "key2"
null | null | null | "a@test" | "key2" | "{ \"a@test\" : { \"key2\" : \"Avalue3\" } }" | "a@test" | "key4"
}

@Unroll
def "exception in @Deprecated getAccountDetails"(Account issuer, String accountId, String writer, String key) {
given:
def qapi = new QueryAPI(api, issuer)

when:
qapi.getAccountDetails(accountId, writer, key)
qapi.getAccountDetails(accountId, writer, key, 1)

then:
thrown ErrorResponseException

where:
issuer | accountId | writer | key
A | "nonexistent@domain" | null | null
issuer | accountId | writer | key
A | "nonexistent@domain" | null | null
}

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

where:
issuer | accountId | writer | key | pageSize
A | "invalid" | null | null | 10
A | null | null | null | -10
A | null | null | null | 0
issuer | accountId | writer | key | pageSize
A | "invalid" | null | null | 10
A | null | null | null | -10
A | null | null | null | 0
}

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

where:
issuer | accountId | writer | key | pageSize
A | "nonexistent@domain" | null | null | 10
issuer | accountId | writer | key | pageSize
A | "nonexistent@domain" | null | null | 10
}

@Unroll
Expand Down

0 comments on commit 3cac393

Please sign in to comment.