0

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
    );
  });
});

1 Answer 1

0

Realized how to do it from this post and also the official docs

Need to use the connect() method, keeping in mind you pass in the full SignerWithAddress object and NOT SignerWithAddress.address

await this.token
  .connect(approved) // <- The solution
  .transferFrom(
    owner.address,
    anotherOwner.address,
    tokenId,
    {
      from: approved.address // <- Optional, to be more explicit
    }
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.