"Creating Dex" Error

So, I have implemented the code for this particular video, however I am getting an error in the dex.sol file from the syntax on line 20. It seems to be the same implementation he used, except I have updated the compiler version to the most recent because I errors I was getting for using the compiler version he implemented. What changes or updates do I need to make to my code to reconcile these version discrepancies? https://github.com/aelkins3/DEX201.git

1 Like

@thecil @mcgrane5 :+1:

2 Likes

what is the exact issue your fscing @limitlessandrew can u share screenshots

1 Like

Notice the red squiggly line on line 20. I’ve made a mistake somewhere, or it has to do with a compiler version difference I think. How am I initializing the mapping incorrectly?

1 Like

you need to give yout mappung a name

1 Like

Ok. Can you show me the new syntax? He didn’t do that in the video. What resource would you use to look this up? Solidity docs? It’s also a double mapping.

2 Likes

alls you need to do is to name your mapping, its not a versuion errir but your decloration of the mappping is incorrrect
mapping(bytes32 => mapping(uint => Order[]))
this is incorrect as you need to gibe the mapping an identifirer or name. s like
mapping(bytes32 => mapping(uint => Order[])) Orderbook;
should worrk

1 Like

Ok this is where I am now. I think you guys may need to update this portion of the course. Because it’s not working the same way with the current compiler version. But if you will help me work through it, I can justify keeping my subscription…

1 Like

You are not importing that contract, thats why error “identifier not found…”

Remember that you need to import "./Wallet.sol" so your Dex knows exactly where to inherit that contract.

Carlos Z

1 Like

We fixed those prior errors. This is what I’m facing now. It says the transaction exited with an error because the Token does not exist. He doesn’t get this error in the video. @thecil

https://github.com/aelkins3/DEX201

2 Likes

You might have to initialize first the contract, then it should be ready to run in the test

    //set contracts instances
    before(async function() {
        // Deploy tokens to testnet
        linkInstance = await ERC20.link.new();
        walletInstance = await Wallet.new();

        console.log("LINK ",linkInstance.address);
        console.log("WALLET ",walletInstance.address);
    });

You can add this inside the contract body, just before all your test. should look something like this

  // Main function that is executed during the test
  contract("DEX", ([owner, account2, account3]) => {
    // Global variable declarations
    let linkInstance;
    let walletInstance;

    //set contracts instances
    before(async function() {
        // Deploy tokens to testnet
        linkInstance = await ERC20.link.new();
        walletInstance = await Wallet.new();

        console.log("LINK ",linkInstance.address);
        console.log("WALLET ",walletInstance.address);
    });

    describe("DEX", () => {

        it("1. DEX test", async function (){
            ...
        });
}

That way, it will deploy a new instance of each contract before running the tests.

Carlos Z

2 Likes

Which contract? dex.sol or wallettest.js? This is what wallettest.js looks like currently based on Philip’s code in the video. @thecil

1 Like

The DEX needs to have the wallet and a token already deployed, so using before will deploy a new instance of the contracts you need before the unit test start.

    //set contracts instances
    before(async function() {
        // Deploy tokens to testnet
        linkInstance = await ERC20.link.new();
        walletInstance = await Wallet.new();

        console.log("LINK ",linkInstance.address);
        console.log("WALLET ",walletInstance.address);
    });

Then, you can use those instances to refer to a contract, like linkInstance.balanceOf() for example.

Carlos Z

2 Likes

@thecil @mcgrane5
Alright, this is my new implementation and result. There still is an error, but I know this is the right direction. I think I’m not understanding the correct way to declare the instances here. Specifically, the difference between new(), your code, and deploy(), Philip’s code, or if I should use both declarations. If you can point me to the right changes to make, I know I’ve almost got it! See the code and output below, pls&thx.

1 Like

at code line 15, remove ERC20 from Link.new().

Then, you should be able to use your contracts by calling the instance of each.
This is how your unit test structure should looks like:
PD: im not importing the wallet contract because my DEX inherit it, therefore when i initialize the dex, it will initialize the wallet contract.

//Contracts
const Link = artifacts.require("Link");
const Dex = artifacts.require("Dex");

// Main function that is executed during the test
contract("DEX", ([owner, alice, bob]) => {

    // Global variable declarations
    let linkInstance;
    let dexInstance;

    // Global functions
    // convert any number into wei
    let _qtyEth = function(_amount) {
        return (web3.utils.toWei(_amount.toString(), "ether"))
    }
    
    // get the symbol of a contract
    async function _symbol(_tokenInstance){
        let _res = await _tokenInstance.symbol();
        _res = web3.utils.fromUtf8(_res);
        return _res;
    }

    //set contracts instances
    before(async function() {
        // Deploy tokens to testnet
        linkInstance = await link.new(_qtyEth(1000));
        dexInstance = await Dex.new();
    });

    describe("DEX", () => {

        it("1. DEPOSIT TOKEN: addToken, approve, deposit tokens correctly, emit Approval event", async function (){
            _ticker = await _symbol(linkInstance);
            await dexInstance.addToken( _ticker, linkInstance.address);

            const _linkApprove = await linkInstance.approve( dexInstance.address , _qtyEth(100) ,{from: owner}) ;
            await dexInstance.depositToken( _qtyEth(1) , _ticker ,{from: owner});

            expectEvent(_linkApprove, 'Approval', {
                owner: owner,
                spender: dexInstance.address,
                value: _qtyEth(100)
            });
        });

     }
}

Carlos Z

@thcil
Alright, I’ll look over this and see how I can reconcile it with Philip and my code. Honestly, it’s a bit frustrating that this part of the course is this challenging. Something is wrong.

Something’s got to give here guys! @thecil @mcgrane5 Here’s a screenshot. I continue to get the same error. None of this instruction is working for me…?

1 Like

hey @limitlessandrew can u share your githib repo ill clone it and fix them for you

1 Like

https://github.com/aelkins3/DEX201

Thank you my friend.

1 Like

cool im out atm but ill be back to you by tonight with the fixes and a detailed report explaining where you went wrong and what i changed

1 Like