Willy
Willy

Reputation: 23

TypeError: Invalid type for argument in function call. Invalid implicit conversion from uint256[3] memory to uint256[] memory requested

so I got a problem while developing a contract using a foundry. So I have a function that takes uint256 with array type as an argument. But when I did the test, It showed an implicit error.

TypeError: Invalid type for argument in function call. Invalid implicit conversion from uint256[3] memory to uint256[] memory requested.

contract Test {
    uint256[] private threshold = [1000, 2000, 3000];

    function setThreshold(uint256[] memory _threshold) public onlyOwner {       
        threshold = _threshold;
    }
}

Does anybody know how to fix this problem?

Upvotes: 2

Views: 1610

Answers (1)

Kuba -a
Kuba -a

Reputation: 11

There is probably an error in your script where you call setThreshold function or error is in your tests.

I've made little changes to your code for simpler check

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

contract Test {
    uint256[] public threshold = [21000, 2000, 3000];

    function setThreshold(uint256[] memory _threshold) public {
        threshold = _threshold;
    }
}

Here is my deploy script: from brownie import Test, accounts

def main():
    check = Test.deploy({"from": accounts[0]})
    print(check.threshold(0))
    check.setThreshold([1000, 1000, 1000], {"from": accounts[0]})
    print(check.threshold(0))

And here is an output:

Running 'scripts/deploy.py::main'... Transaction sent: 0x63fba19e52cb9064c43d25f76b43151ddc5cbf4ba55ca30f469322eeabd824bf Gas price: 0.0 gwei Gas limit: 12000000 Nonce: 0 Test.constructor confirmed Block: 1 Gas used: 257509 (2.15%) Test deployed at: 0x3194cBDC3dbcd3E11a07892e7bA5c3394048Cc87 21000 Transaction sent: 0xe48cd3a8231fdc4e246b5e93aa1fc4544dabce6ef4f19bfd65fb8044d42ad9db Gas price: 0.0 gwei Gas limit: 12000000 Nonce: 1 Test.setThreshold confirmed Block: 2 Gas used: 39640 (0.33%) 1000 Terminating local RPC client...

Upvotes: 0

Related Questions