Running the code below returns a vm error:

Error: Returned error: VM Exception while processing transaction: revert at Object.ErrorResponse (node_modules/truffle/build/webpack:/~/web3-eth/~/web3-core-helpers/src/errors.js:29:1) at node_modules/truffle/build/webpack:/~/web3-eth/~/web3-core-requestmanager/src/index.js:140:1 at node_modules/truffle/build/webpack:/packages/truffle-provider/wrapper.js:112:1 at XMLHttpRequest.request.onreadystatechange (node_modules/truffle/build/webpack:/~/web3/~/web3-providers-http/src/index.js:96:1) at XMLHttpRequestEventTarget.dispatchEvent (node_modules/truffle/build/webpack:/~/xhr2-cookies/dist/xml-http-request-event-target.js:34:1) at XMLHttpRequest._setReadyState (node_modules/truffle/build/webpack:/~/xhr2-cookies/dist/xml-http-request.js:208:1) at XMLHttpRequest._onHttpResponseEnd (node_modules/truffle/build/webpack:/~/xhr2-cookies/dist/xml-http-request.js:318:1) at IncomingMessage. (node_modules/truffle/build/webpack:/~/xhr2-cookies/dist/xml-http-request.js:289:47) at endReadableNT (_stream_readable.js:1094:12) at process._tickCallback (internal/process/next_tick.js:63:19)

The error is triggered on the await this.token1.safeTransferFrom(holder1, this.AS.address, transferAmount, _data)

The code called is the same as safeTransferFrom() in the ERC721 standard here called OCT. Also the AS contract correctly implements the onERC721Received() since its a contract.

const {BN} = require('openzeppelin-test-helpers');

const OCT = artifacts.require('OCT');
const Swap = artifacts.require('Swap');

contract('Swap & OCT', function ([_, holder1, holder2, recipient, anotherAccount]) {
    const initialSupply = new BN(100);
    const transferAmount = new BN(10);

    beforeEach(async function () {
      this.token1 = await OCT.new("OpsCoin", "OCT", 20, holder1, initialSupply);
      this.token2 = await OCT.new("OpsCoin", "OCT", 20, holder2, initialSupply);
      this.AS = await Swap.new();
    describe('Atomic Swap', function () {
        describe('Deploy two uERC20 Contracts that empty their amounts into their owners accounts', function () {
            it('Return two contracts and their Supply', async function () {
                (await this.token1.totalSupply()).should.be.bignumber.equal(initialSupply);
                (await this.token2.totalSupply()).should.be.bignumber.equal(initialSupply);

        describe('Initiate the Swap', function () {
            it('Run the code for Atomic Swap by running safeTransferFrom()', async function () {
                //Encode the data into a bytes var so the safeTransferFrom can pass it over to the Swap Contract
                var _data = await web3.eth.abi.encodeParameters   (  
                    ['1', transferAmount.toString(), holder2, this.token1.address, transferAmount.toString(), this.token2.address]

                var data = await web3.eth.abi.encodeParameters   (  
                    ['uint256', 'uint256','address','address','uint256','address'], 
                    ['1', transferAmount.toString(), holder1, this.token2.address, transferAmount.toString(), this.token1.address]

                //Send the tokens to the ASContract triggering the lead of the swap
                await this.token1.safeTransferFrom(holder1, this.AS.address, transferAmount, _data)


I realise this is a heavy and difficult question but Ill be very grateful to whom ever can fix it

Your Answer

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

Browse other questions tagged or ask your own question.