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

feature request: support async function when mocking return #107

Open
marcelomorgado opened this issue Jan 17, 2022 · 3 comments
Open

feature request: support async function when mocking return #107

marcelomorgado opened this issue Jan 17, 2022 · 3 comments
Labels
bounty bug Something isn't working

Comments

@marcelomorgado
Copy link

Is your feature request related to a problem? Please describe.
I was not able to pass an async function in order to return a dynamic value, only when the function is sync it works fine.

Describe the solution you'd like

myFake.myFunction.returns(async () => { ... })
@kbrizzle
Copy link

kbrizzle commented Feb 7, 2022

+1

@arjun-io
Copy link

arjun-io commented Feb 7, 2022

I can confirm this doesn't work, if you modify the async test case here: https://github.com/defi-wonderland/smock/blob/main/test/unit/programmable-function-logic/type-handling.spec.ts#L237 to something like

it('should wait for result as promise', async () => {
  const asyncRequest = (n: number) => {
    return new Promise(function (resolve) {
      setTimeout(() => {
        resolve(n * 10);
      }, 10)
    });
  };
  fake.getInputtedUint256.returns(async (number: number) => asyncRequest(number));

  expect(await fake.callStatic.getInputtedUint256(10)).to.equal(100);
});

it will fail. I believe this is an issue with performing an async action within RxJS's .subscribe but I'm not sure what the right fix is.

@smartcontracts smartcontracts added the bug Something isn't working label Mar 16, 2022
@wei3erHase wei3erHase changed the title Support async function when mocking return feature request: support async function when mocking return Jun 17, 2022
@robercano
Copy link

I created some tests some time ago to also demonstrate the issue. You can find them here: #143

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bounty bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants