|
| 1 | +package com.openelements.hiero.base.test.data; |
| 2 | + |
| 3 | +import com.hedera.hashgraph.sdk.ContractId; |
| 4 | +import com.openelements.hiero.base.data.ContractEventInstance; |
| 5 | +import com.openelements.hiero.base.data.ContractLog; |
| 6 | +import com.openelements.hiero.smartcontract.abi.model.AbiEvent; |
| 7 | +import com.openelements.hiero.smartcontract.abi.model.AbiParameter; |
| 8 | +import com.openelements.hiero.smartcontract.abi.model.AbiParameterType; |
| 9 | +import java.util.List; |
| 10 | +import org.junit.jupiter.api.Assertions; |
| 11 | +import org.junit.jupiter.api.Test; |
| 12 | + |
| 13 | +public class ContractLogTest { |
| 14 | + |
| 15 | + @Test |
| 16 | + void test() { |
| 17 | + //given |
| 18 | + // from https://testnet.mirrornode.hedera.com/api/v1/contracts/0.0.5615061/results/logs?limit=10&order=asc |
| 19 | + final String address = "0x000000000000000000000000000000000055add5"; |
| 20 | + final String bloom = "0x00000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000"; |
| 21 | + final ContractId contractId = ContractId.fromString("0.0.5615061"); |
| 22 | + final String data = "0x0000000000000000000000000000000000000000000000000000000000000001"; |
| 23 | + final long index = 1; |
| 24 | + final List<String> topics = List.of("0x271219bdbb9b91472a5df68ef7a9d3f8de02f3c27b93a35306f888acf081ea60"); |
| 25 | + final String block_hash = "0x3c33e36ebaa60192ff6c714ec15adb3829e8dd24e0f28b607fa88f6052600fb07ab29aeeb828e3faffd85b90960cc679"; |
| 26 | + final long blockNumber = 16076698; |
| 27 | + final ContractId rootContractId = ContractId.fromString("0.0.5615061"); |
| 28 | + final String timestamp = "1740183080.776076000"; |
| 29 | + final String transactionHash = "0x254fa8781dc4babe1df5925bc2e3e8aa50d1b57d019189116f93fbdbb5497812"; |
| 30 | + final Long transactionIndex = 6L; |
| 31 | + final ContractLog contractLog = new ContractLog(address, bloom, contractId, data, index, topics, block_hash, |
| 32 | + blockNumber, rootContractId, timestamp, transactionHash, transactionIndex); |
| 33 | + final List<AbiParameter> inputs = List.of( |
| 34 | + new AbiParameter("count", AbiParameterType.UINT, List.of(), false) |
| 35 | + ); |
| 36 | + final AbiEvent event = new AbiEvent("MissingVerificationCountUpdated", inputs, false); |
| 37 | + |
| 38 | + //then |
| 39 | + Assertions.assertTrue(contractLog.isEventOfType(event)); |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + void test2() { |
| 44 | + //given |
| 45 | + // from https://testnet.mirrornode.hedera.com/api/v1/contracts/0.0.5615061/results/logs?limit=10&order=asc |
| 46 | + final String address = "0x000000000000000000000000000000000055add5"; |
| 47 | + final String bloom = "0x00000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000"; |
| 48 | + final ContractId contractId = ContractId.fromString("0.0.5615061"); |
| 49 | + final String data = "0x0000000000000000000000000000000000000000000000000000000000000001"; |
| 50 | + final long index = 1; |
| 51 | + final List<String> topics = List.of("0x271219bdbb9b91472a5df68ef7a9d3f8de02f3c27b93a35306f888acf081ea60"); |
| 52 | + final String block_hash = "0x3c33e36ebaa60192ff6c714ec15adb3829e8dd24e0f28b607fa88f6052600fb07ab29aeeb828e3faffd85b90960cc679"; |
| 53 | + final long blockNumber = 16076698; |
| 54 | + final ContractId rootContractId = ContractId.fromString("0.0.5615061"); |
| 55 | + final String timestamp = "1740183080.776076000"; |
| 56 | + final String transactionHash = "0x254fa8781dc4babe1df5925bc2e3e8aa50d1b57d019189116f93fbdbb5497812"; |
| 57 | + final Long transactionIndex = 6L; |
| 58 | + final ContractLog contractLog = new ContractLog(address, bloom, contractId, data, index, topics, block_hash, |
| 59 | + blockNumber, rootContractId, timestamp, transactionHash, transactionIndex); |
| 60 | + final List<AbiParameter> inputs = List.of( |
| 61 | + new AbiParameter("count", AbiParameterType.UINT, List.of(), false) |
| 62 | + ); |
| 63 | + final AbiEvent event = new AbiEvent("MissingVerificationCountUpdated", inputs, false); |
| 64 | + |
| 65 | + //when |
| 66 | + final ContractEventInstance eventInstance = contractLog.asEventInstance(event); |
| 67 | + |
| 68 | + //then |
| 69 | + Assertions.assertNotNull(eventInstance); |
| 70 | + Assertions.assertEquals(contractId, eventInstance.contractId()); |
| 71 | + Assertions.assertEquals("MissingVerificationCountUpdated", eventInstance.eventName()); |
| 72 | + Assertions.assertEquals(1, eventInstance.parameters().size()); |
| 73 | + Assertions.assertEquals("count", eventInstance.parameters().get(0).name()); |
| 74 | + Assertions.assertEquals(AbiParameterType.UINT, eventInstance.parameters().get(0).type()); |
| 75 | + Assertions.assertArrayEquals( |
| 76 | + new byte[]{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 77 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 78 | + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 79 | + 0x00, 0x01}, |
| 80 | + eventInstance.parameters().get(0).value()); |
| 81 | + } |
| 82 | + |
| 83 | +} |
0 commit comments