Skip to content

Commit

Permalink
fix: bring changes to v1 contracts for testing
Browse files Browse the repository at this point in the history
This commit can be reverted or the changes removed when done, but will show that both the core-v2 tests still pass after the change, and adds a new test to ensure both CityCoins and STX are transferred when claiming in the current cycle.

This will also provide an artifact of the testing with the related github action.
  • Loading branch information
whoabuddy committed May 5, 2022
1 parent 67d94aa commit 859791b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 6 deletions.
7 changes: 5 additions & 2 deletions contracts/cities/mia/local/miamicoin-core-v1.clar
Original file line number Diff line number Diff line change
Expand Up @@ -630,8 +630,11 @@
)
(match (get-reward-cycle stacksHeight)
currentCycle
(if (or (<= currentCycle targetCycle) (is-eq u0 userStackedThisCycle))
;; this cycle hasn't finished, or Stacker contributed nothing
(if (and (not (var-get isShutdown))
(or (<= currentCycle targetCycle) (is-eq u0 userStackedThisCycle)))
;; the contract is not shut down and
;; this cycle hasn't finished
;; or stacker contributed nothing
u0
;; (totalUstxThisCycle * userStackedThisCycle) / totalStackedThisCycle
(/ (* totalUstxThisCycle userStackedThisCycle) totalStackedThisCycle)
Expand Down
7 changes: 5 additions & 2 deletions contracts/cities/nyc/local/newyorkcitycoin-core-v1.clar
Original file line number Diff line number Diff line change
Expand Up @@ -634,8 +634,11 @@
)
(match (get-reward-cycle stacksHeight)
currentCycle
(if (or (<= currentCycle targetCycle) (is-eq u0 userStackedThisCycle))
;; this cycle hasn't finished, or Stacker contributed nothing
(if (and (not (var-get isShutdown))
(or (<= currentCycle targetCycle) (is-eq u0 userStackedThisCycle)))
;; the contract is not shut down and
;; this cycle hasn't finished
;; or stacker contributed nothing
u0
;; (totalUstxThisCycle * userStackedThisCycle) / totalStackedThisCycle
(/ (* totalUstxThisCycle userStackedThisCycle) totalStackedThisCycle)
Expand Down
27 changes: 26 additions & 1 deletion tests/cities/mia/upgrade/miamicoin-core-v1-v2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ describe("[MiamiCoin Upgrade v1-v2]", () => {
block.receipts[2].result.expectOk().expectBool(true);
});

it("claim-stacking-reward() succeeds in v1 with current reward cycle after shutdown and returns CityCoins without returning STX", () => {
it.skip("claim-stacking-reward() succeeds in v1 with current reward cycle after shutdown and returns CityCoins without returning STX", () => {
// this confirms a known bug in `get-entitled-stacking-reward`
// arrange
const targetCycle = 16;
Expand All @@ -424,6 +424,31 @@ describe("[MiamiCoin Upgrade v1-v2]", () => {
);
});

it("claim-stacking-reward() succeeds in v1 with current reward cycle after shutdown and returns CityCoins and STX", () => {
// this confirms a the bug fix for `get-entitled-stacking-reward`
// arrange
const targetCycle = 16;
// act
const block = chain.mineBlock([
core.claimStackingReward(targetCycle, user2)
]);
const receipt = block.receipts[0];
// assert
receipt.result.expectOk().expectBool(true);
assertEquals(receipt.events.length, 2);
receipt.events.expectFungibleTokenTransferEvent(
1000,
core.address,
user2.address,
"miamicoin"
);
receipt.events.expectSTXTransferEvent(
35000,
core.address,
user2.address
);
});

it("claim-stacking-reward() succeeds in v1 with current reward cycle after shutdown and returns CityCoins and STX", () => {
// this mitigates a known bug in `get-entitled-stacking-reward`
// arrange
Expand Down
27 changes: 26 additions & 1 deletion tests/cities/nyc/upgrade/newyorkcitycoin-core-v1-v2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ describe("[NewYorkCityCoin Upgrade v1-v2]", () => {
block.receipts[2].result.expectOk().expectBool(true);
});

it("claim-stacking-reward() succeeds in v1 with current reward cycle after shutdown and returns CityCoins without returning STX", () => {
it.skip("claim-stacking-reward() succeeds in v1 with current reward cycle after shutdown and returns CityCoins without returning STX", () => {
// this confirms a known bug in `get-entitled-stacking-reward`
// arrange
const targetCycle = 10;
Expand All @@ -424,6 +424,31 @@ describe("[NewYorkCityCoin Upgrade v1-v2]", () => {
);
});

it("claim-stacking-reward() succeeds in v1 with current reward cycle after shutdown and returns CityCoins and STX", () => {
// this confirms a the bug fix for `get-entitled-stacking-reward`
// arrange
const targetCycle = 16;
// act
const block = chain.mineBlock([
core.claimStackingReward(targetCycle, user2)
]);
const receipt = block.receipts[0];
// assert
receipt.result.expectOk().expectBool(true);
assertEquals(receipt.events.length, 2);
receipt.events.expectFungibleTokenTransferEvent(
1000,
core.address,
user2.address,
"newyorkcitycoin"
);
receipt.events.expectSTXTransferEvent(
35000,
core.address,
user2.address
);
});

it("claim-stacking-reward() succeeds in v1 with current reward cycle after shutdown and returns CityCoins and STX", () => {
// this mitigates a known bug in `get-entitled-stacking-reward`
// arrange
Expand Down

0 comments on commit 859791b

Please sign in to comment.