Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wierd behaviour with encodeABI #30

Open
Smrt666 opened this issue Aug 31, 2023 · 0 comments
Open

Wierd behaviour with encodeABI #30

Smrt666 opened this issue Aug 31, 2023 · 0 comments

Comments

@Smrt666
Copy link

Smrt666 commented Aug 31, 2023

I am using your library to test a smart contract that requires another one. I am also using npx hardhat test test/simpleTest.ts for testing. I am not sure if this is a bug or just me doing something I shouldn't. Here is my code for test/simpleTest.ts:

import { MockContractInstance, PChainStakeMirrorVerifierInstance, PChainStakeMirrorVerifierMockInstance } from "../../../../typechain-truffle";
import type { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { BN } from "bn.js";
import { ethers } from 'hardhat';

import { abi } from "../artifacts/contracts/Random.sol/Random.json"

import { RandomContract, RouletteContract, RouletteInstance } from '../typechain-types/';
import { RandomInstance } from "../typechain-types/contracts/Random";

const MockContract = artifacts.require("MockContract");
const Roulette: RouletteContract = artifacts.require('Roulette');
const Random: RandomInstance = artifacts.require('Random');

function bn(n: any) {
    return new BN(n.toString());
}

const IRandom = new web3.eth.Contract(
    abi as any
)

describe('Roulette', async () => {
    let roulette: RouletteInstance
    let owner: SignerWithAddress
    let randomMock: MockContractInstance

    beforeEach(async () => {

        
        randomMock = await MockContract.new();
        const methodGetRandom = IRandom.methods.getRandom(25).encodeABI()

        // await ethers.getSigners();
        [owner] = await ethers.getSigners();

        randomMock.givenCalldataReturn(
            methodGetRandom, 
            web3.eth.abi.encodeParameters(["uint256", "bool"], [12345 , true])
        )

        console.log(owner);
    })
})

This code produces TypeError: Cannot create property 'undefined' on string '0xcd4b69140000000000000000000000000000000000000000000000000000000000000019'. If I uncomment // await ethers.getSigners();, it works.

If I move randomMock... above getting owner, then owner is undefined. Again uncommenting that await ... line makes it work again.

I hope either I am doing something wrong or it helps you improve your library. If you need more information I can provide it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant