|
| 1 | +import { Address, BigInt, Bytes, ethereum } from "@graphprotocol/graph-ts"; |
| 2 | +import { |
| 3 | + assert, |
| 4 | + beforeAll, |
| 5 | + describe, |
| 6 | + newMockEvent, |
| 7 | + test, |
| 8 | +} from "matchstick-as/assembly/index"; |
| 9 | +import { handleNameUnwrapped } from "../src/nameWrapper"; |
| 10 | +import { NameUnwrapped } from "../src/types/NameWrapper/NameWrapper"; |
| 11 | +import { Domain, WrappedDomain } from "../src/types/schema"; |
| 12 | +import { ETH_NODE } from "../src/utils"; |
| 13 | +import { DEFAULT_OWNER, setEthOwner } from "./testUtils"; |
| 14 | + |
| 15 | +beforeAll(() => { |
| 16 | + setEthOwner(); |
| 17 | +}); |
| 18 | + |
| 19 | +const NAME_WRAPPER_ADDRESS = "0xD4416b13d2b3a9aBae7AcD5D6C2BbDBE25686401"; |
| 20 | +// test.eth |
| 21 | +const testEthNamehash = |
| 22 | + "0xeb4f647bea6caa36333c816d7b46fdcb05f9466ecacc140ea8c66faf15b3d9f1"; |
| 23 | + |
| 24 | +const createNameUnwrappedEvent = ( |
| 25 | + node: string, |
| 26 | + owner: string |
| 27 | +): NameUnwrapped => { |
| 28 | + let mockEvent = newMockEvent(); |
| 29 | + let newNameUnwrappedEvent = new NameUnwrapped( |
| 30 | + mockEvent.address, |
| 31 | + mockEvent.logIndex, |
| 32 | + mockEvent.transactionLogIndex, |
| 33 | + mockEvent.logType, |
| 34 | + mockEvent.block, |
| 35 | + mockEvent.transaction, |
| 36 | + mockEvent.parameters, |
| 37 | + mockEvent.receipt |
| 38 | + ); |
| 39 | + newNameUnwrappedEvent.parameters = new Array(); |
| 40 | + let nodeParam = new ethereum.EventParam( |
| 41 | + "node", |
| 42 | + ethereum.Value.fromBytes(Bytes.fromHexString(node)) |
| 43 | + ); |
| 44 | + let ownerParam = new ethereum.EventParam( |
| 45 | + "owner", |
| 46 | + ethereum.Value.fromAddress(Address.fromString(owner)) |
| 47 | + ); |
| 48 | + newNameUnwrappedEvent.parameters.push(nodeParam); |
| 49 | + newNameUnwrappedEvent.parameters.push(ownerParam); |
| 50 | + return newNameUnwrappedEvent; |
| 51 | +}; |
| 52 | + |
| 53 | +describe("handleNameUnwrapped", () => { |
| 54 | + test("does not set expiryDate to null if name is .eth", () => { |
| 55 | + // test |
| 56 | + const labelhash = |
| 57 | + "0x9c22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb658"; |
| 58 | + |
| 59 | + let domain = new Domain(testEthNamehash); |
| 60 | + domain.name = "test.eth"; |
| 61 | + domain.labelName = "test"; |
| 62 | + domain.labelhash = Bytes.fromHexString(labelhash); |
| 63 | + domain.parent = ETH_NODE; |
| 64 | + domain.subdomainCount = 0; |
| 65 | + domain.isMigrated = true; |
| 66 | + domain.createdAt = BigInt.fromI32(0); |
| 67 | + domain.owner = NAME_WRAPPER_ADDRESS; |
| 68 | + domain.registrant = NAME_WRAPPER_ADDRESS; |
| 69 | + domain.wrappedOwner = DEFAULT_OWNER; |
| 70 | + domain.expiryDate = BigInt.fromI32(123456789); |
| 71 | + domain.save(); |
| 72 | + |
| 73 | + const wrappedDomain = new WrappedDomain(testEthNamehash); |
| 74 | + wrappedDomain.domain = testEthNamehash; |
| 75 | + wrappedDomain.expiryDate = BigInt.fromI32(123456789); |
| 76 | + wrappedDomain.fuses = 0; |
| 77 | + wrappedDomain.owner = DEFAULT_OWNER; |
| 78 | + wrappedDomain.name = "test.eth"; |
| 79 | + wrappedDomain.save(); |
| 80 | + |
| 81 | + const nameUnwrappedEvent = createNameUnwrappedEvent( |
| 82 | + testEthNamehash, |
| 83 | + DEFAULT_OWNER |
| 84 | + ); |
| 85 | + |
| 86 | + handleNameUnwrapped(nameUnwrappedEvent); |
| 87 | + |
| 88 | + assert.fieldEquals("Domain", testEthNamehash, "expiryDate", "123456789"); |
| 89 | + }); |
| 90 | + test("sets expiryDate to null if name is not .eth", () => { |
| 91 | + // cool.test.eth |
| 92 | + const subNamehash = |
| 93 | + "0x85c47d906feeeed4795f21773ab20983af35e85837d2de39549f650c8fb50c0f"; |
| 94 | + // cool |
| 95 | + const labelhash = |
| 96 | + "0x678c189fde5058554d934d6af17e41750fa2a94b61371c5ea958a7595e146324"; |
| 97 | + |
| 98 | + let domain = new Domain(subNamehash); |
| 99 | + domain.name = "cool.test.eth"; |
| 100 | + domain.labelName = "cool"; |
| 101 | + domain.labelhash = Bytes.fromHexString(labelhash); |
| 102 | + domain.parent = testEthNamehash; |
| 103 | + domain.subdomainCount = 0; |
| 104 | + domain.isMigrated = true; |
| 105 | + domain.createdAt = BigInt.fromI32(0); |
| 106 | + domain.owner = NAME_WRAPPER_ADDRESS; |
| 107 | + domain.registrant = NAME_WRAPPER_ADDRESS; |
| 108 | + domain.wrappedOwner = DEFAULT_OWNER; |
| 109 | + domain.expiryDate = BigInt.fromI32(123456789); |
| 110 | + domain.save(); |
| 111 | + |
| 112 | + const wrappedDomain = new WrappedDomain(subNamehash); |
| 113 | + wrappedDomain.domain = subNamehash; |
| 114 | + wrappedDomain.expiryDate = BigInt.fromI32(123456789); |
| 115 | + wrappedDomain.fuses = 0; |
| 116 | + wrappedDomain.owner = DEFAULT_OWNER; |
| 117 | + wrappedDomain.name = "test.eth"; |
| 118 | + wrappedDomain.save(); |
| 119 | + |
| 120 | + const nameUnwrappedEvent = createNameUnwrappedEvent( |
| 121 | + subNamehash, |
| 122 | + DEFAULT_OWNER |
| 123 | + ); |
| 124 | + |
| 125 | + handleNameUnwrapped(nameUnwrappedEvent); |
| 126 | + |
| 127 | + assert.fieldEquals("Domain", subNamehash, "expiryDate", "null"); |
| 128 | + }); |
| 129 | +}); |
0 commit comments