LimeChain / matchstick

🔥 Unit testing framework for Subgraph development on The Graph protocol. ⚙️
MIT License
207 stars 17 forks source link

Bug: unable to point multiple `@derivedFrom`s at the same entity #333

Closed grezle closed 2 years ago

grezle commented 2 years ago

Given the following schema:

type Parent1 @entity {
    id: ID!
    children: [Child!]! @derivedFrom(field: "parent1")
}

type Parent2 @entity {
    id: ID!
    children: [Child!]! @derivedFrom(field: "parent2")
}

type Child @entity {
    id: ID!
    parent1: Parent1!
    parent2: Parent2!
}

And a mapping which sets the Parents against the Child:

export function handleSetParents(): void {
    let parent1 = Parent1.load('1')
    parent1 = parent1 === null ? new Parent1('1') : parent1

    parent1.save()

    let parent2 = Parent2.load('2')
    parent2 = parent2 === null ? new Parent2('2') : parent2

    parent2.save()

    let child = Child.load('3')
    child = child === null ? new Child('3') : child

    child.parent1 = parent1.id
    child.parent2 = parent2.id

    child.save()
}

We would expect to be able to test that the association is made when we call handleSetParents from a test:

// this test passes
test('derived fields associating the parent and child are created', () => {
    handleSetParents()

    assert.fieldEquals('Parent2', '2', 'children', `[3]`)
})

... however ...


// this fails with an error like: `...  with message: unexpected null, wasm backtrace: ...`
test('derived fields associating the parent and child are created', () => {
    handleSetParents()

    assert.fieldEquals('Parent1', '1', 'children', `[3]`)
    assert.fieldEquals('Parent2', '2', 'children', `[3]`)
})