Skip to content
This repository has been archived by the owner on Mar 8, 2021. It is now read-only.

ethers.js - problem with function overloading in Solidity contracts #14

Open
SvenMeyer opened this issue Dec 21, 2020 · 1 comment
Open

Comments

@SvenMeyer
Copy link

I have a simple Solidity contract. The functions which do not exist with different parameter signatures (no function overloading) work fine in a Hardhat , Waffle , Chai , TypeScript test setup, but fail if the function exists with different function signatures ...

pragma solidity ^0.7.0;

contract StakingContract {

	function getStakedAmount(address user) public pure returns (uint) {
		// return uint(user) & 0x7;	// return 0..7
		return (user == address(0x0)) ? 0 : 1; // one ticket for every account, no matter how much staked
	}

	function getStakedAmount() public view returns (uint) {
    	return getStakedAmount(msg.sender);
	}
}
import { Signer } from "@ethersproject/abstract-signer";
import { ethers, waffle } from "hardhat";
import { expect } from "chai";
import { Accounts, Signers } from "../types";

import StakingContractArtifact from "../artifacts/contracts/StakingContract.sol/StakingContract.json";
import ProbTokenSaleArtifact   from "../artifacts/contracts/ProbTokenSale.sol/ProbTokenSale.json";

import { StakingContract } from "../typechain/StakingContract";
import { ProbTokenSale }   from "../typechain/ProbTokenSale";

const { deployContract } = waffle;

const max_tickets = 1000;
const tickets_per_stake = 1;

describe("ProbTokenSale", function () {

  before(async function () {
    this.accounts = {} as Accounts;
    this.signers  = {} as Signers;

    const signers: Signer[] = await ethers.getSigners();
    this.signers.admin = signers[0];
    this.accounts.admin = await signers[0].getAddress();
    console.log("account:", this.accounts.admin);

    this.stake = (await deployContract(this.signers.admin, StakingContractArtifact, [])) as StakingContract;
    this.pts   = (await deployContract(this.signers.admin, ProbTokenSaleArtifact, [max_tickets, tickets_per_stake])) as ProbTokenSale;
  });

  it("user account can call StakingContract.getStakedAmount", async function () {
    expect(await this.stake.connect(this.signers.admin).getStakedAmount()).to.equal(1);
  });

});
     TypeError: this.stake.connect(...).getStakedAmount is not a function
      at Context.<anonymous> (test/ProbTokenSale.ts:33:57)
      at step (test/ProbTokenSale.ts:33:23)
      at Object.next (test/ProbTokenSale.ts:14:53)
      at /home/sum/DEV/ETH/ZeroSwap/zeroswap-dto-lottery-nft/test/ProbTokenSale.ts:8:71
      at new Promise (<anonymous>)
      at __awaiter (test/ProbTokenSale.ts:4:12)
      at Context.<anonymous> (test/ProbTokenSale.ts:81:16)

Any idea what is wrong ?

@SvenMeyer
Copy link
Author

SvenMeyer commented Dec 23, 2020

Looks like it is more an issue with ethers.js

tasitlabs/tasit-sdk#172

ethers-io/ethers.js#950

ethers-io/ethers.js#1160

Any chance that a TypeScript approach may provide a better solution ?

@SvenMeyer SvenMeyer changed the title problems with function overloading in Solidity contracts ? ethers.js - problem with function overloading in Solidity contracts Dec 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant