Skip to content

Commit

Permalink
Add test, bump version, update smoke
Browse files Browse the repository at this point in the history
  • Loading branch information
kronosapiens committed Jul 19, 2022
1 parent e6537cf commit a3a3c90
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
3 changes: 2 additions & 1 deletion contracts/extensions/CoinMachine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ contract CoinMachine is ColonyExtension, BasicMetaTransaction {

/// @notice Returns the version of the extension
function version() public override pure returns (uint256) {
return 5;
return 6;
}

/// @notice Configures the extension
Expand Down Expand Up @@ -279,6 +279,7 @@ contract CoinMachine is ColonyExtension, BasicMetaTransaction {
// Update the price
activePrice = wdiv(emaIntake, targetPerPeriod);
}

activeIntake = 0;
activeSold = 0;

Expand Down
2 changes: 1 addition & 1 deletion test-smoke/colony-storage-consistent.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ contract("Contract Storage", (accounts) => {
console.log("miningCycleStateHash:", miningCycleAccount.stateRoot.toString("hex"));
console.log("tokenLockingStateHash:", tokenLockingAccount.stateRoot.toString("hex"));

expect(colonyNetworkAccount.stateRoot.toString("hex")).to.equal("329bb37f05a543fad925845a53366700392f905814799f205929eaaad20e320a");
expect(colonyNetworkAccount.stateRoot.toString("hex")).to.equal("3ae9f034f263a6fc4934d575114cfd729408600547d52414b5371cf106508cb0");
expect(colonyAccount.stateRoot.toString("hex")).to.equal("e77447c223f5bdfee71413e843a505316693368b74c1930ec27d3c1c944450fb");
expect(metaColonyAccount.stateRoot.toString("hex")).to.equal("58f1833f0b94c47c028c91ededb70d6697624ecf98bc2cc7930bf55f40d2d931");
expect(miningCycleAccount.stateRoot.toString("hex")).to.equal("1f3909ac9098d953ec1d197e6d7924384e96209770f445466ea2f0c0c39f4834");
Expand Down
25 changes: 25 additions & 0 deletions test/extensions/coin-machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,31 @@ contract("Coin Machine", (accounts) => {
expect(currentPrice).to.eq.BN(expectedPrice);
});

it("can correctly account for sold tokens between periods when adding a balance", async () => {
coinMachine = await deployCoinMachine(OWNER);

await purchaseToken.mint(OWNER, WAD.muln(10), { from: OWNER });
await purchaseToken.approve(coinMachine.address, WAD.muln(10), { from: OWNER });

// Iniitalise with a zero balance, then add tokens
await coinMachine.initialise(tokens, times, 60 * 60, 10, targets, limits, WAD, UINT128_MAX, true, ADDRESS_ZERO, ADDRESS_ZERO);
await token.mint(coinMachine.address, WAD.muln(200));

const periodLength = await coinMachine.periodLength();

let activeSold;

await coinMachine.buyTokens(WAD, { from: OWNER });
activeSold = await coinMachine.activeSold();
expect(activeSold).to.eq.BN(WAD);

await forwardTime(periodLength.toNumber(), this);

await coinMachine.buyTokens(WAD, { from: OWNER });
activeSold = await coinMachine.activeSold();
expect(activeSold).to.eq.BN(WAD);
});

it("it monotonically adjusts prices according to demand", async () => {
const periodLength = await coinMachine.getPeriodLength();
const maxPerPeriod = await coinMachine.getMaxPerPeriod();
Expand Down

0 comments on commit a3a3c90

Please sign in to comment.