Skip to content

Commit

Permalink
regression tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tbrent committed Oct 16, 2023
1 parent 42a119b commit 8a26bbf
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
9 changes: 8 additions & 1 deletion contracts/plugins/mocks/AssetMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ pragma solidity 0.8.19;
import "../assets/Asset.sol";

contract AssetMock is Asset {
bool public stale;

uint192 private lowPrice;
uint192 private highPrice;

Expand Down Expand Up @@ -40,13 +42,18 @@ contract AssetMock is Asset {
uint192
)
{
require(!stale, "stale price");
return (lowPrice, highPrice, 0);
}

/// Should not revert
/// Refresh saved prices
function refresh() public virtual override {
// pass
stale = false;
}

function setStale(bool _stale) external {
stale = _stale;
}

function setPrice(uint192 low, uint192 high) external {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,41 @@ const collateralSpecificStatusTests = () => {
// refresh() should not revert
await collateral.refresh()
})

it('Regression test -- refreshes inner RTokenAsset on refresh()', async () => {
const [collateral] = await deployCollateral({})
const initialPrice = await collateral.price()
expect(initialPrice[0]).to.be.gt(0)
expect(initialPrice[1]).to.be.lt(MAX_UINT192)

// Swap out eUSD's RTokenAsset with a mock one
const AssetMockFactory = await ethers.getContractFactory('AssetMock')
const mockRTokenAsset = await AssetMockFactory.deploy(
bn('1'), // unused
ONE_ADDRESS, // unused
bn('1'), // unused
eUSD,
bn('1'), // unused
bn('1') // unused
)
const eUSDAssetRegistry = await ethers.getContractAt(
'IAssetRegistry',
'0x9B85aC04A09c8C813c37de9B3d563C2D3F936162'
)
await whileImpersonating('0xc8Ee187A5e5c9dC9b42414Ddf861FFc615446a2c', async (signer) => {
await eUSDAssetRegistry.connect(signer).swapRegistered(mockRTokenAsset.address)
})

// Set RTokenAsset price to stale
await mockRTokenAsset.setStale(true)
expect(await mockRTokenAsset.stale()).to.be.true

// Refresh CurveStableRTokenMetapoolCollateral
await collateral.refresh()

// Stale should be false again
expect(await mockRTokenAsset.stale()).to.be.false
})
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,41 @@ const collateralSpecificStatusTests = () => {
// refresh() should not revert
await collateral.refresh()
})

it('Regression test -- refreshes inner RTokenAsset on refresh()', async () => {
const [collateral] = await deployCollateral({})
const initialPrice = await collateral.price()
expect(initialPrice[0]).to.be.gt(0)
expect(initialPrice[1]).to.be.lt(MAX_UINT192)

// Swap out eUSD's RTokenAsset with a mock one
const AssetMockFactory = await ethers.getContractFactory('AssetMock')
const mockRTokenAsset = await AssetMockFactory.deploy(
bn('1'), // unused
ONE_ADDRESS, // unused
bn('1'), // unused
eUSD,
bn('1'), // unused
bn('1') // unused
)
const eUSDAssetRegistry = await ethers.getContractAt(
'IAssetRegistry',
'0x9B85aC04A09c8C813c37de9B3d563C2D3F936162'
)
await whileImpersonating('0xc8Ee187A5e5c9dC9b42414Ddf861FFc615446a2c', async (signer) => {
await eUSDAssetRegistry.connect(signer).swapRegistered(mockRTokenAsset.address)
})

// Set RTokenAsset price to stale
await mockRTokenAsset.setStale(true)
expect(await mockRTokenAsset.stale()).to.be.true

// Refresh CurveStableRTokenMetapoolCollateral
await collateral.refresh()

// Stale should be false again
expect(await mockRTokenAsset.stale()).to.be.false
})
}

/*
Expand Down

0 comments on commit 8a26bbf

Please sign in to comment.