Skip to content

Add documentation and a unit test for returning multiple arrays in a smocked function #1228

@wei3erHase

Description

@wei3erHase

When trying to mock an UniswapV3Pool, to be accessed through the Oracle library, we're pointing to the observe(secondsAgo) function.

Code to be used in our contract:
(int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s) = IUniswapV3Pool(pool).observe(secondsAgos);

UniswapV3Pool.sol :

Oracle.Observation[65535] public override observations;
    [...]
    /// LINE 236
    function observe(uint32[] calldata secondsAgos)
        external
        view
        override
        noDelegateCall
        returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s)
    {  ...  }

When trying to smock the answer of the address, have tried multiple options:
pool.smocked.observe.will.return.with([ 1, 1 ])
pool.smocked.observe.will.return.with([ [1], [1] ])

'tickCumulatives':1,
'secondsPerLiquidityCumulativeX128s':1
})
pool.smocked.observe.will.return.with({
'tickCumulatives':[1,2,3],
'secondsPerLiquidityCumulativeX128s':[1,2,3]
})

I've tried also replacing the numbers with BigNumber.from(0) but still, every try I'm getting the following error Error: Transaction reverted: function returned an unexpected amount of data

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-featureCategory: features

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions