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)!");
}
}
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);
}
}
}
}
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);
}
}
}
Aggregations