ethereum / remix-vscode

Remix VS Code extension
96 stars 20 forks source link

Error when i try to deploy Contract with library #26

Open azanux opened 2 years ago

azanux commented 2 years ago

It 's been 2 days , I am trying to deploy a Smart Contract , this Smart Contract is linked to a Library , but I am gettin an error when I try to deploy The Smart Contract TestIterable.sol . I am using Ethereum Remix IDE with visual studio

There are errors deploying: Error: The data field must be HEX encoded data.

The same source code is working in Remix IDE (web version)

See the source code below

`

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

library IterableMapping {
    // Iterable mapping from address to uint;
    struct Map {
        address[] keys;
        mapping(address => uint) values;
        mapping(address => uint) indexOf;
        mapping(address => bool) inserted;
    }

    function get(Map storage map, address key) public view returns (uint) {
        return map.values[key];
    }

    function getKeyAtIndex(Map storage map, uint index) public view returns (address) {
        return map.keys[index];
    }

    function size(Map storage map) public view returns (uint) {
        return map.keys.length;
    }

    function set(
        Map storage map,
        address key,
        uint val
    ) public {
        if (map.inserted[key]) {
            map.values[key] = val;
        } else {
            map.inserted[key] = true;
            map.values[key] = val;
            map.indexOf[key] = map.keys.length;
            map.keys.push(key);
        }
    }

    function remove(Map storage map, address key) public {
        if (!map.inserted[key]) {
            return;
        }

        delete map.inserted[key];
        delete map.values[key];

        uint index = map.indexOf[key];
        uint lastIndex = map.keys.length - 1;
        address lastKey = map.keys[lastIndex];

        map.indexOf[lastKey] = index;
        delete map.indexOf[key];

        map.keys[index] = lastKey;
        map.keys.pop();
    }
}

contract TestIterableMap {
    using IterableMapping for IterableMapping.Map;

    IterableMapping.Map private map ;

    function testIterableMap() public {
        map.set(address(0x0), 0);
        map.set(address(0x1), 100);
        map.set(address(0x2), 200); // insert
        map.set(address(0x2), 200); // update
        map.set(address(0x3), 300);

        for (uint i = 0; i < map.size(); i++) {
            address key = map.getKeyAtIndex(i);

            assert(map.get(key) == i * 100);
        }

        map.remove(address(1));

        // keys = [address(0), address(3), address(2)]
        assert(map.size() == 3);
        assert(map.getKeyAtIndex(0) == address(0));
        assert(map.getKeyAtIndex(1) == address(3));
        assert(map.getKeyAtIndex(2) == address(2));
    }
}

`

JYBWOB commented 1 year ago

I have the same question with u. Have you solved it?

azanux commented 1 year ago

no ! i switch to Remix IDE on Desktop