I'm trying to write a test to check if an approved address can transfer the owner's token. However, whenever I try to call token.transferFrom()
with a transactionObject of {from: approved.address}
, it errors out with:
Error: Contract with a Signer cannot override from
(operation="overrides.from", code=UNSUPPORTED_OPERATION, version=contracts/5.6.0)
It seems the transferObject only accepts a {from: owner.address}
because the owner is the one who received the minted token.
How can I properly override the transactionObject in order to test an approved address calling the method?
Relevant code is below...
context("given approvals", function () {
beforeEach(async function () {
// The sender (owner) allows the approved address to mess with this one NFT
await token.approve(approved.address, tokenId, {
from: owner.address,
});
});
// This works
it("should allow the owner to transfer the token", async function () {
await this.token.transferFrom(
owner.address,
anotherOwner.address,
tokenId,
{
from: owner.address, // <- This works since it's from the owner
}
);
expect(await this.token.ownerOf(tokenId)).to.be.equal(
anotherOwner.address
);
});
// This does not work
// Error: Contract with a Signer cannot override from
it("should allow the approved address to transfer the token", async function () {
await this.token.transferFrom(
owner.address,
anotherOwner.address,
tokenId,
{
from: approved.address, // <- This doesn't work and errors
}
);
expect(await this.token.ownerOf(tokenId)).to.be.equal(
anotherOwner.address
);
});
});