|
| 1 | +import { ethereum } from "@graphprotocol/graph-ts"; |
| 2 | +import { |
| 3 | + afterAll, |
| 4 | + assert, |
| 5 | + beforeAll, |
| 6 | + clearStore, |
| 7 | + createMockedFunction, |
| 8 | + describe, |
| 9 | + newMockEvent, |
| 10 | + test, |
| 11 | +} from "matchstick-as"; |
| 12 | +import { |
| 13 | + MintParcel, |
| 14 | + SurveyParcel, |
| 15 | +} from "../../generated/RealmDiamond/RealmDiamond"; |
| 16 | +import { |
| 17 | + BIGINT_EIGHT, |
| 18 | + BIGINT_FIVE, |
| 19 | + BIGINT_FOUR, |
| 20 | + BIGINT_ONE, |
| 21 | + BIGINT_SEVEN, |
| 22 | + BIGINT_SIX, |
| 23 | + BIGINT_THREE, |
| 24 | + BIGINT_TWO, |
| 25 | + REALM_DIAMOND, |
| 26 | +} from "../../src/helper/constants"; |
| 27 | +import { handleMintParcel, handleSurveyParcel } from "../../src/mappings/realm"; |
| 28 | + |
| 29 | +let mockEvent = newMockEvent(); |
| 30 | +let realmId = BIGINT_ONE; |
| 31 | +let round = BIGINT_TWO; |
| 32 | +describe("handleSurveyParcel", () => { |
| 33 | + beforeAll(() => { |
| 34 | + // prepare event |
| 35 | + let event = new SurveyParcel( |
| 36 | + mockEvent.address, |
| 37 | + mockEvent.logIndex, |
| 38 | + mockEvent.transactionLogIndex, |
| 39 | + mockEvent.logType, |
| 40 | + mockEvent.block, |
| 41 | + mockEvent.transaction, |
| 42 | + mockEvent.parameters, |
| 43 | + null |
| 44 | + ); |
| 45 | + |
| 46 | + event.parameters.push( |
| 47 | + new ethereum.EventParam( |
| 48 | + "_tokenId", |
| 49 | + ethereum.Value.fromUnsignedBigInt(realmId) |
| 50 | + ) |
| 51 | + ); |
| 52 | + |
| 53 | + event.parameters.push( |
| 54 | + new ethereum.EventParam( |
| 55 | + "_round", |
| 56 | + ethereum.Value.fromUnsignedBigInt(round) |
| 57 | + ) |
| 58 | + ); |
| 59 | + |
| 60 | + event.parameters.push( |
| 61 | + new ethereum.EventParam( |
| 62 | + "_alchemicas", |
| 63 | + ethereum.Value.fromUnsignedBigIntArray([ |
| 64 | + BIGINT_TWO, |
| 65 | + BIGINT_TWO, |
| 66 | + BIGINT_TWO, |
| 67 | + BIGINT_TWO, |
| 68 | + ]) |
| 69 | + ) |
| 70 | + ); |
| 71 | + |
| 72 | + // mock getParcelInfo |
| 73 | + let tuple: ethereum.Tuple = changetype<ethereum.Tuple>([ |
| 74 | + ethereum.Value.fromString("A"), |
| 75 | + ethereum.Value.fromString("B"), |
| 76 | + ethereum.Value.fromAddress(REALM_DIAMOND), |
| 77 | + ethereum.Value.fromUnsignedBigInt(BIGINT_ONE), |
| 78 | + ethereum.Value.fromUnsignedBigInt(BIGINT_TWO), |
| 79 | + ethereum.Value.fromUnsignedBigInt(BIGINT_THREE), |
| 80 | + ethereum.Value.fromUnsignedBigInt(BIGINT_FOUR), |
| 81 | + ethereum.Value.fromUnsignedBigIntArray([ |
| 82 | + BIGINT_FIVE, |
| 83 | + BIGINT_SIX, |
| 84 | + BIGINT_SEVEN, |
| 85 | + BIGINT_EIGHT, |
| 86 | + ]), |
| 87 | + ]); |
| 88 | + createMockedFunction( |
| 89 | + REALM_DIAMOND, |
| 90 | + "getParcelInfo", |
| 91 | + "getParcelInfo(uint256):((string,string,address,uint256,uint256,uint256,uint256,uint256[4]))" |
| 92 | + ) |
| 93 | + .withArgs([ethereum.Value.fromUnsignedBigInt(realmId)]) |
| 94 | + .returns([ethereum.Value.fromTuple(tuple)]); |
| 95 | + |
| 96 | + handleSurveyParcel(event); |
| 97 | + }); |
| 98 | + |
| 99 | + test("it should has remainingAlchemica field", () => { |
| 100 | + assert.fieldEquals("Parcel", "1", "remainingAlchemica", "[2, 2, 2, 2]"); |
| 101 | + }); |
| 102 | + |
| 103 | + afterAll(() => { |
| 104 | + clearStore(); |
| 105 | + }); |
| 106 | +}); |
0 commit comments