Search in sources :

Example 1 with MigrationContractResult

use of com.hedera.mirror.importer.migration.ContractResultMigration.MigrationContractResult in project hedera-mirror-node by hashgraph.

the class ContractResultMigrationTest method migrate.

@SuppressWarnings("deprecation")
@Test
void migrate() throws Exception {
    ContractFunctionResult.Builder functionResult = contractFunctionResult();
    MigrationContractResult contractResult = contractResult(functionResult);
    insert(contractResult);
    contractResultMigration.doMigrate();
    ContractLoginfo loginfo = functionResult.getLogInfo(0);
    assertThat(getContractLogs()).hasSize(1).first().returns(loginfo.getBloom().toByteArray(), MigrationContractLog::getBloom).returns(contractResult.getConsensusTimestamp(), MigrationContractLog::getConsensusTimestamp).returns(loginfo.getContractID().getContractNum(), MigrationContractLog::getContractId).returns(0, MigrationContractLog::getIndex).returns(Hex.encodeHexString(loginfo.getTopic(0).toByteArray()), MigrationContractLog::getTopic0).returns(Hex.encodeHexString(loginfo.getTopic(1).toByteArray()), MigrationContractLog::getTopic1).returns(Hex.encodeHexString(loginfo.getTopic(2).toByteArray()), MigrationContractLog::getTopic2).returns(Hex.encodeHexString(loginfo.getTopic(3).toByteArray()), MigrationContractLog::getTopic3);
    assertThat(getContractResults()).hasSize(1).first().returns(functionResult.getBloom().toByteArray(), MigrationContractResult::getBloom).returns(contractResult.getConsensusTimestamp(), MigrationContractResult::getConsensusTimestamp).returns(functionResult.getContractCallResult().toByteArray(), MigrationContractResult::getCallResult).returns(functionResult.getContractID().getContractNum(), MigrationContractResult::getContractId).returns(functionResult.getErrorMessage(), MigrationContractResult::getErrorMessage).returns(functionResult.getCreatedContractIDsList().stream().map(EntityId::of).map(EntityId::getId).toArray(Long[]::new), MigrationContractResult::getCreatedContractIds);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) MigrationContractResult(com.hedera.mirror.importer.migration.ContractResultMigration.MigrationContractResult) MigrationContractLog(com.hedera.mirror.importer.migration.ContractResultMigration.MigrationContractLog) ContractLoginfo(com.hederahashgraph.api.proto.java.ContractLoginfo) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 2 with MigrationContractResult

use of com.hedera.mirror.importer.migration.ContractResultMigration.MigrationContractResult in project hedera-mirror-node by hashgraph.

the class ContractResultMigrationTest method migrateWhenEmptyTopic.

@Test
void migrateWhenEmptyTopic() throws Exception {
    ContractFunctionResult.Builder functionResult = contractFunctionResult();
    functionResult.setLogInfo(0, functionResult.getLogInfoBuilder(0).clearTopic().addTopic(ByteString.copyFrom(new byte[0])));
    MigrationContractResult contractResult = contractResult(functionResult);
    insert(contractResult);
    contractResultMigration.doMigrate();
    assertThat(getContractLogs()).hasSize(1).first().returns("", MigrationContractLog::getTopic0).returns(null, MigrationContractLog::getTopic1).returns(null, MigrationContractLog::getTopic2).returns(null, MigrationContractLog::getTopic3);
}
Also used : ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) MigrationContractResult(com.hedera.mirror.importer.migration.ContractResultMigration.MigrationContractResult) MigrationContractLog(com.hedera.mirror.importer.migration.ContractResultMigration.MigrationContractLog) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 3 with MigrationContractResult

use of com.hedera.mirror.importer.migration.ContractResultMigration.MigrationContractResult in project hedera-mirror-node by hashgraph.

the class ContractResultMigrationTest method migrateWhenEmptyContractIDs.

@Test
void migrateWhenEmptyContractIDs() throws Exception {
    ContractFunctionResult.Builder functionResult = contractFunctionResult().clearContractID().clearCreatedContractIDs().addCreatedContractIDs(ContractID.getDefaultInstance());
    MigrationContractResult contractResult = contractResult(functionResult);
    insert(contractResult);
    contractResultMigration.doMigrate();
    assertThat(getContractResults()).hasSize(1).first().returns(null, MigrationContractResult::getContractId).returns(new Long[] { null }, MigrationContractResult::getCreatedContractIds);
}
Also used : ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) MigrationContractResult(com.hedera.mirror.importer.migration.ContractResultMigration.MigrationContractResult) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 4 with MigrationContractResult

use of com.hedera.mirror.importer.migration.ContractResultMigration.MigrationContractResult in project hedera-mirror-node by hashgraph.

the class ContractResultMigrationTest method contractResult.

private MigrationContractResult contractResult(ContractFunctionResult.Builder functionResult) {
    MigrationContractResult migrationContractResult = new MigrationContractResult();
    migrationContractResult.setConsensusTimestamp(++id);
    migrationContractResult.setFunctionParameters(new byte[] { 6, 7, 8 });
    migrationContractResult.setFunctionResult(functionResult.build().toByteArray());
    return migrationContractResult;
}
Also used : MigrationContractResult(com.hedera.mirror.importer.migration.ContractResultMigration.MigrationContractResult)

Example 5 with MigrationContractResult

use of com.hedera.mirror.importer.migration.ContractResultMigration.MigrationContractResult in project hedera-mirror-node by hashgraph.

the class ContractResultMigrationTest method migrateWhenNoProtobufData.

@Test
void migrateWhenNoProtobufData() throws Exception {
    MigrationContractResult migrationContractResult1 = contractResult();
    migrationContractResult1.setFunctionResult(null);
    insert(migrationContractResult1);
    MigrationContractResult migrationContractResult2 = contractResult();
    migrationContractResult2.setFunctionResult(new byte[0]);
    insert(migrationContractResult2);
    MigrationContractResult migrationContractResult3 = contractResult();
    migrationContractResult3.setFunctionResult(new byte[] { 0, 1, 2 });
    insert(migrationContractResult3);
    contractResultMigration.doMigrate();
    assertThat(getContractLogs()).isEmpty();
    assertThat(getContractResults()).hasSize(3).describedAs("Fields have not been migrated").extracting(MigrationContractResult::getContractId).allMatch(Objects::isNull);
}
Also used : MigrationContractResult(com.hedera.mirror.importer.migration.ContractResultMigration.MigrationContractResult) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Aggregations

MigrationContractResult (com.hedera.mirror.importer.migration.ContractResultMigration.MigrationContractResult)5 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)4 Test (org.junit.jupiter.api.Test)4 ContractFunctionResult (com.hederahashgraph.api.proto.java.ContractFunctionResult)3 MigrationContractLog (com.hedera.mirror.importer.migration.ContractResultMigration.MigrationContractLog)2 EntityId (com.hedera.mirror.common.domain.entity.EntityId)1 ContractLoginfo (com.hederahashgraph.api.proto.java.ContractLoginfo)1 Objects (java.util.Objects)1