|
2 | 2 | import sys
|
3 | 3 | import os
|
4 | 4 |
|
5 |
| -sys.path.append(os.path.dirname("ccdefundamentals")) |
| 5 | + |
| 6 | +sys.path.append(os.path.dirname("ccdexplorer_fundamentals")) |
6 | 7 | from ccdexplorer_fundamentals.GRPCClient import GRPCClient
|
7 | 8 | from rich import print
|
8 | 9 | from ccdexplorer_fundamentals.enums import NET
|
| 10 | +from ccdexplorer_fundamentals.mongodb import MongoDB, Collections |
| 11 | +from ccdexplorer_schema_parser.Schema import Schema |
9 | 12 | from ccdexplorer_fundamentals.cis import (
|
10 | 13 | CIS,
|
11 | 14 | registerCredentialEvent,
|
12 | 15 | revokeCredentialEvent,
|
13 | 16 | transferEvent,
|
14 | 17 | tokenMetadataEvent,
|
| 18 | + itemCreatedEvent, |
| 19 | + itemStatusChangedEvent, |
15 | 20 | )
|
| 21 | +from ccdexplorer_fundamentals.GRPCClient.CCD_Types import CCD_ContractAddress |
16 | 22 |
|
17 | 23 |
|
18 | 24 | @pytest.fixture
|
19 | 25 | def grpcclient():
|
20 | 26 | return GRPCClient()
|
21 | 27 |
|
22 | 28 |
|
| 29 | +@pytest.fixture |
| 30 | +def mongodb(): |
| 31 | + return MongoDB(tooter=None) |
| 32 | + |
| 33 | + |
23 | 34 | def tx_at_index_from(
|
24 | 35 | tx_index: int,
|
25 | 36 | block_hash: str,
|
@@ -151,3 +162,85 @@ def test_checksum_other2(grpcclient: GRPCClient):
|
151 | 162 | assert tag == 251
|
152 | 163 | assert result.token_id == "25"
|
153 | 164 | assert result.metadata.checksum is None
|
| 165 | + |
| 166 | + |
| 167 | +def get_schema_from_source( |
| 168 | + contract_address: CCD_ContractAddress, |
| 169 | + mongodb: MongoDB, |
| 170 | + grpcclient: GRPCClient, |
| 171 | + net: NET, |
| 172 | +): |
| 173 | + result = mongodb.testnet[Collections.instances].find_one( |
| 174 | + {"_id": contract_address.to_str()} |
| 175 | + ) |
| 176 | + module_ref = ( |
| 177 | + result["v1"]["source_module"] |
| 178 | + if result.get("v1") |
| 179 | + else result["v0"]["source_module"] |
| 180 | + ) |
| 181 | + source_module_name = ( |
| 182 | + result["v1"]["name"][5:] if result.get("v1") else result["v0"]["name"][5:] |
| 183 | + ) |
| 184 | + ms = grpcclient.get_module_source_original_classes( |
| 185 | + module_ref, "last_final", net=net |
| 186 | + ) |
| 187 | + schema = Schema(ms.v1.value, 1) if ms.v1 else Schema(ms.v0.value, 0) |
| 188 | + |
| 189 | + return schema, source_module_name |
| 190 | + |
| 191 | + |
| 192 | +def test_cis_6_create_item( |
| 193 | + grpcclient: GRPCClient, |
| 194 | + mongodb: MongoDB, |
| 195 | +): |
| 196 | + net = NET.TESTNET |
| 197 | + block_hash = grpcclient.get_finalized_block_at_height(13753259, net).hash |
| 198 | + tx = tx_at_index_from(0, block_hash, grpcclient, net) |
| 199 | + # print(tx) |
| 200 | + contract_address = CCD_ContractAddress(index=8901, subindex=0) |
| 201 | + schema, source_module_name = get_schema_from_source( |
| 202 | + contract_address, mongodb, grpcclient, net |
| 203 | + ) |
| 204 | + ci = CIS(grpcclient, contract_address.index, contract_address.subindex, "", net) |
| 205 | + |
| 206 | + event = tx.account_transaction.effects.contract_update_issued.effects[0] |
| 207 | + tag, result = ci.process_tnt_log_event(event.updated.events[0]) |
| 208 | + |
| 209 | + if tag == 237: |
| 210 | + event_json = schema.event_to_json( |
| 211 | + source_module_name, |
| 212 | + bytes.fromhex(event.updated.events[0]), |
| 213 | + ) |
| 214 | + |
| 215 | + result: itemCreatedEvent |
| 216 | + result.initial_status = list( |
| 217 | + event_json["ItemCreated"][0]["initial_status"].keys() |
| 218 | + )[0] |
| 219 | + print(result) |
| 220 | + |
| 221 | + |
| 222 | +def test_cis_6_status_changed_item(grpcclient: GRPCClient, mongodb: MongoDB): |
| 223 | + net = NET.TESTNET |
| 224 | + block_hash = grpcclient.get_finalized_block_at_height(13757068, net).hash |
| 225 | + tx = tx_at_index_from(0, block_hash, grpcclient, net) |
| 226 | + # print(tx) |
| 227 | + contract_address = CCD_ContractAddress(index=8901, subindex=0) |
| 228 | + schema, source_module_name = get_schema_from_source( |
| 229 | + contract_address, mongodb, grpcclient, net |
| 230 | + ) |
| 231 | + ci = CIS(grpcclient, contract_address.index, contract_address.subindex, "", net) |
| 232 | + |
| 233 | + event = tx.account_transaction.effects.contract_update_issued.effects[0] |
| 234 | + tag, result = ci.process_tnt_log_event(event.updated.events[0]) |
| 235 | + |
| 236 | + if tag == 236: |
| 237 | + event_json = schema.event_to_json( |
| 238 | + source_module_name, |
| 239 | + bytes.fromhex(event.updated.events[0]), |
| 240 | + ) |
| 241 | + |
| 242 | + result: itemStatusChangedEvent |
| 243 | + result.new_status = list( |
| 244 | + event_json["ItemStatusChanged"][0]["new_status"].keys() |
| 245 | + )[0] |
| 246 | + print(result) |
0 commit comments