-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix!: rights conservation should allow new brands or dropped brands i…
…f sum is empty (#3036) * fix!: rights conservation should allow for the introduction or drop of brands as long as the sum is empty * chore: use a set of allBrands
- Loading branch information
1 parent
53645d4
commit 56c5943
Showing
2 changed files
with
125 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// @ts-check | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { test } from '@agoric/zoe/tools/prepare-test-env-ava'; | ||
|
||
import { amountMath } from '@agoric/ertp'; | ||
|
||
import { setupZCFTest } from './setupZcfTest'; | ||
|
||
test(`zcfSeat.stage, zcf.reallocate introducing new empty amount`, async t => { | ||
const { zcf } = await setupZCFTest(); | ||
const { zcfSeat: zcfSeat1 } = zcf.makeEmptySeatKit(); | ||
const { zcfSeat: zcfSeat2 } = zcf.makeEmptySeatKit(); | ||
const zcfMint = await zcf.makeZCFMint('RUN'); | ||
const { brand } = zcfMint.getIssuerRecord(); | ||
|
||
// Get the amount allocated on zcfSeat1. It is empty for the RUN brand. | ||
const allocation = zcfSeat1.getAmountAllocated('RUN', brand); | ||
t.true(amountMath.isEmpty(allocation)); | ||
|
||
// Stage zcfSeat2 with the allocation from zcfSeat1 | ||
const zcfSeat2Staging = zcfSeat2.stage({ RUN: allocation }); | ||
|
||
// Stage zcfSeat1 with empty | ||
const zcfSeat1Staging = zcfSeat1.stage({ RUN: amountMath.makeEmpty(brand) }); | ||
|
||
zcf.reallocate(zcfSeat1Staging, zcfSeat2Staging); | ||
|
||
t.deepEqual(zcfSeat1.getCurrentAllocation(), { | ||
RUN: amountMath.make(0n, brand), | ||
}); | ||
t.deepEqual(zcfSeat2.getCurrentAllocation(), { | ||
RUN: amountMath.make(0n, brand), | ||
}); | ||
}); | ||
|
||
test(`zcfSeat.stage, zcf.reallocate "dropping" empty amount`, async t => { | ||
const { zcf } = await setupZCFTest(); | ||
const { zcfSeat: zcfSeat1 } = zcf.makeEmptySeatKit(); | ||
const { zcfSeat: zcfSeat2 } = zcf.makeEmptySeatKit(); | ||
const zcfMint = await zcf.makeZCFMint('RUN'); | ||
const { brand } = zcfMint.getIssuerRecord(); | ||
|
||
zcfMint.mintGains({ RUN: amountMath.make(brand, 0n) }, zcfSeat1); | ||
zcfMint.mintGains({ RUN: amountMath.make(brand, 0n) }, zcfSeat2); | ||
|
||
// Now zcfSeat1 and zcfSeat2 both have an empty allocation for RUN. | ||
t.deepEqual(zcfSeat1.getCurrentAllocation(), { | ||
RUN: amountMath.make(0n, brand), | ||
}); | ||
t.deepEqual(zcfSeat2.getCurrentAllocation(), { | ||
RUN: amountMath.make(0n, brand), | ||
}); | ||
|
||
// Stage zcfSeat1 with an entirely empty allocation | ||
const zcfSeat1Staging = zcfSeat2.stage({}); | ||
|
||
// Stage zcfSeat2 with an entirely empty allocation | ||
const zcfSeat2Staging = zcfSeat1.stage({}); | ||
|
||
// Because of how we merge staged allocations with the current | ||
// allocation (we don't delete keys), the RUN keyword still remains: | ||
t.deepEqual(zcfSeat1Staging.getStagedAllocation(), { | ||
RUN: amountMath.make(0n, brand), | ||
}); | ||
t.deepEqual(zcfSeat2Staging.getStagedAllocation(), { | ||
RUN: amountMath.make(0n, brand), | ||
}); | ||
|
||
zcf.reallocate(zcfSeat1Staging, zcfSeat2Staging); | ||
|
||
// The reallocation succeeds without error, but because of how we | ||
// merge new allocations with old allocations (we don't delete | ||
// keys), the RUN keyword still remains as is. | ||
t.deepEqual(zcfSeat1.getCurrentAllocation(), { | ||
RUN: amountMath.make(0n, brand), | ||
}); | ||
t.deepEqual(zcfSeat2.getCurrentAllocation(), { | ||
RUN: amountMath.make(0n, brand), | ||
}); | ||
}); |