Search in sources :

Example 1 with HapiQueryCheckStateException

use of com.hedera.services.bdd.spec.exceptions.HapiQueryCheckStateException in project hedera-services by hashgraph.

the class HapiGetContractRecords method checkExpectations.

private void checkExpectations(HapiApiSpec spec, List<TransactionRecord> records) throws Throwable {
    String specExpectationsDir = specScopedDir(spec, expectationsDirPath);
    try {
        String expectationsDir = specExpectationsDir + "/" + contract;
        File countFile = new File(expectationsDir + "/n.txt");
        CharSource charSource = Files.asCharSource(countFile, Charset.forName("UTF-8"));
        int n = Integer.parseInt(charSource.readFirstLine());
        Assertions.assertEquals(n, records.size(), "Bad number of records!");
        for (int i = 0; i < n; i++) {
            File recordFile = new File(expectationsDir + "/record" + i + ".bin");
            ByteSource byteSource = Files.asByteSource(recordFile);
            TransactionRecord expected = TransactionRecord.parseFrom(byteSource.read());
            Assertions.assertEquals(expected, records.get(i), "Wrong record #" + i);
        }
    } catch (Exception e) {
        if (log.isDebugEnabled()) {
            log.error("Something amiss with the expected records...", e);
        } else {
            log.error("Something amiss with the expected records {}", records);
        }
        throw new HapiQueryCheckStateException("Impossible to meet expectations (on records)!");
    }
}
Also used : CharSource(com.google.common.io.CharSource) ByteSource(com.google.common.io.ByteSource) File(java.io.File) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) HapiQueryCheckStateException(com.hedera.services.bdd.spec.exceptions.HapiQueryCheckStateException) HapiQueryCheckStateException(com.hedera.services.bdd.spec.exceptions.HapiQueryCheckStateException)

Example 2 with HapiQueryCheckStateException

use of com.hedera.services.bdd.spec.exceptions.HapiQueryCheckStateException in project hedera-services by hashgraph.

the class ExpectedTokenRel method assertNoUnexpectedRels.

public static void assertNoUnexpectedRels(String account, List<String> expectedAbsent, List<TokenRelationship> actualRels, HapiApiSpec spec) {
    for (String unexpectedToken : expectedAbsent) {
        for (TokenRelationship actualRel : actualRels) {
            var unexpectedId = spec.registry().getTokenID(unexpectedToken);
            if (actualRel.getTokenId().equals(unexpectedId)) {
                String errMsg = String.format("Account '%s' should have had no relationship with token '%s'!", account, unexpectedToken);
                log.error(errMsg);
                throw new HapiQueryCheckStateException(errMsg);
            }
        }
    }
}
Also used : HapiQueryCheckStateException(com.hedera.services.bdd.spec.exceptions.HapiQueryCheckStateException) TokenRelationship(com.hederahashgraph.api.proto.java.TokenRelationship)

Example 3 with HapiQueryCheckStateException

use of com.hedera.services.bdd.spec.exceptions.HapiQueryCheckStateException in project hedera-services by hashgraph.

the class ExpectedTokenRel method assertExpectedRels.

public static void assertExpectedRels(String account, List<ExpectedTokenRel> expectedRels, List<TokenRelationship> actualRels, HapiApiSpec spec) {
    for (ExpectedTokenRel rel : expectedRels) {
        boolean found = false;
        var expectedId = spec.registry().getTokenID(rel.getToken());
        for (TokenRelationship actualRel : actualRels) {
            if (actualRel.getTokenId().equals(expectedId)) {
                found = true;
                rel.getDecimals().ifPresent(d -> assertEquals(d, actualRel.getDecimals()));
                rel.getBalance().ifPresent(a -> assertEquals(a, actualRel.getBalance()));
                rel.getKycStatus().ifPresent(s -> assertEquals(s, actualRel.getKycStatus()));
                rel.getFreezeStatus().ifPresent(s -> assertEquals(s, actualRel.getFreezeStatus()));
            }
        }
        if (!found) {
            String errMsg = String.format("Account '%s' had no relationship with token '%s'!", account, rel.getToken());
            log.error(errMsg);
            throw new HapiQueryCheckStateException(errMsg);
        }
    }
}
Also used : HapiQueryCheckStateException(com.hedera.services.bdd.spec.exceptions.HapiQueryCheckStateException) TokenRelationship(com.hederahashgraph.api.proto.java.TokenRelationship)

Aggregations

HapiQueryCheckStateException (com.hedera.services.bdd.spec.exceptions.HapiQueryCheckStateException)3 TokenRelationship (com.hederahashgraph.api.proto.java.TokenRelationship)2 ByteSource (com.google.common.io.ByteSource)1 CharSource (com.google.common.io.CharSource)1 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)1 File (java.io.File)1