Skip to content

Commit

Permalink
fix lp_stable_decimals_migration tests
Browse files Browse the repository at this point in the history
epicwavesrider committed Aug 26, 2022
1 parent fbb3aa1 commit f5e0d4b
Showing 8 changed files with 14 additions and 105 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@
"test-lp-staking-v2": "mocha --parallel --require test/lp_staking_v2/_hooks.mjs test/lp_staking_v2",
"test-lp": "mocha --parallel --require test/lp/_hooks.mjs test/lp",
"test-lp-stable": "mocha --parallel --require test/lp_stable/_hooks.mjs test/lp_stable",
"test-lp-stable-new-pools-with-different-decimals": "mocha --parallel --require test/lp_stable/new_pools_with_different_decimals/_hooks.mjs test/lp_stable/new_pools_with_different_decimals",
"test-lp-stable-decimals-migration": "mocha --parallel --require test/lp_stable/lp_stable_decimals_migration/_hooks.mjs test/lp_stable/lp_stable_decimals_migration",
"test-lp-to-lp-stable-migration": "mocha --parallel --require test/lp_stable/lp_to_lp_stable_migration/_hooks.mjs test/lp_stable/lp_to_lp_stable_migration",
"test-referral": "mocha --parallel --require test/referral/_hooks.mjs test/referral",
6 changes: 1 addition & 5 deletions test/lp_stable/getOneTkn.mjs
Original file line number Diff line number Diff line change
@@ -22,7 +22,6 @@ describe('lp_stable: getOneTkn.mjs', /** @this {MochaSuiteModified} */() => {
const usdtAmount = 1e8;
const exchResult = 0;
const notUsed = 0;
const delay = 2;

const expectedOutAmAmt = 1e8;
const expectedOutPrAmt = 0;
@@ -47,9 +46,7 @@ describe('lp_stable: getOneTkn.mjs', /** @this {MochaSuiteModified} */() => {
chainId,
}, this.accounts.user1);
await api.transactions.broadcast(putOneTkn, {});
const { height } = await ni.waitForTx(putOneTkn.id, { apiBase });

await ni.waitForHeight(height + delay, { apiBase });
await ni.waitForTx(putOneTkn.id, { apiBase });

const getOneTkn = invokeScript({
dApp: lpStable,
@@ -100,7 +97,6 @@ describe('lp_stable: getOneTkn.mjs', /** @this {MochaSuiteModified} */() => {

expect(stateChanges.invokes.map((item) => [item.dApp, item.call.function]))
.to.deep.include.members([
[address(this.accounts.lpStableAddon, chainId), 'ensureCanGetOneTkn'],
[address(this.accounts.gwxReward, chainId), 'calcD'],
[address(this.accounts.gwxReward, chainId), 'calcD'],
[address(this.accounts.factoryV2, chainId), 'burn'],
61 changes: 11 additions & 50 deletions test/lp_stable/lp_stable_decimals_migration/getOneTkn.mjs
Original file line number Diff line number Diff line change
@@ -26,14 +26,14 @@ describe('lp_stable_decimals_migration: getOneTkn.mjs', /** @this {MochaSuiteMod
const autoStake = false;
const usdtAmount = 1e8;
const usdnAmount = 1e8;
const delay = 2;
const exchResult = 0;
const notUsed = 0;

const expectedOutLpAmt = 1e8;
const expectedOutLpAmt = 1e10;
const expectedPriceLast = 5e7;
const expectedPriceHistory = 5e7;
const expectedInvokesCount = 1;
const expectedInvokesCountOldScript = 4;
const expectedInvokesCountNewScript = 3;

const lpStable = address(this.accounts.lpStable, chainId);

@@ -55,11 +55,10 @@ describe('lp_stable_decimals_migration: getOneTkn.mjs', /** @this {MochaSuiteMod
chainId,
}, this.accounts.user1);
await api.transactions.broadcast(put, {});
const { height } = await ni.waitForTx(put.id, { apiBase });
await ni.waitForTx(put.id, { apiBase });

// putOneTknFirst
// --------------------------------------------------------------------------------------------
await ni.waitForHeight(height + delay + 1, { apiBase });

const putOneTknFirst = invokeScript({
dApp: lpStable,
@@ -110,14 +109,14 @@ describe('lp_stable_decimals_migration: getOneTkn.mjs', /** @this {MochaSuiteMod
const {
timestamp: timestampGetOneTknAfterPutOneTknFirst,
} = await api.blocks.fetchHeadersAt(heightGetOneTknAfterPutOneTknFirst);
const keyPriceHistoryGetOneTknAfterPutOneTknFirst = `%s%s%d%d__price__history__${heightGetOneTknAfterPutOneTknFirst}__${timestampGetOneTknAfterPutOneTknFirstt}`;
const keyPriceHistoryGetOneTknAfterPutOneTknFirst = `%s%s%d%d__price__history__${heightGetOneTknAfterPutOneTknFirst}__${timestampGetOneTknAfterPutOneTknFirst}`;

// check getOneTknAfterPutOneTknFirst
// --------------------------------------------------------------------------------------------
expect(stateChangesGetOneTknAfterPutOneTknFirst.data).to.eql([{
key: `%s%s%s__G__${address(this.accounts.user1, chainId)}__${idGetOneTknAfterPutOneTknFirst}`,
type: 'string',
value: `%d%d%d%d%d%d__${usdtAmount}__${usdnAmount}__${expectedOutLpAmt}__${expectedPriceLast}__${heightGetOneTknAfterPutOneTknFirst}__${timestampGetOneTknAfterPutOneTknFirst}`,
value: `%d%d%d%d%d%d__${usdtAmount}__${notUsed}__${expectedOutLpAmt}__${expectedPriceLast}__${heightGetOneTknAfterPutOneTknFirst}__${timestampGetOneTknAfterPutOneTknFirst}`,
}, {
key: '%s%s__price__last',
type: 'integer',
@@ -132,33 +131,15 @@ describe('lp_stable_decimals_migration: getOneTkn.mjs', /** @this {MochaSuiteMod
address: address(this.accounts.user1, chainId),
asset: this.usdtAssetId,
amount: usdtAmount,
}, {
address: address(this.accounts.user1, chainId),
asset: this.usdnAssetId,
amount: usdnAmount,
}]);

const {
invokes: invokesGetOneTknAfterPutOneTknFirst,
} = stateChangesGetOneTknAfterPutOneTknFirst;
expect(invokesGetOneTknAfterPutOneTknFirst.length).to.eql(expectedInvokesCount);

expect(invokesGetOneTknAfterPutOneTknFirst[0].dApp)
.to.eql(address(this.accounts.factoryV2, chainId));
expect(invokesGetOneTknAfterPutOneTknFirst[0].call.function).to.eql('burn');
expect(invokesGetOneTknAfterPutOneTknFirst[0].call.args).to.eql([
{
type: 'Int',
value: expectedOutLpAmt,
}]);
expect(invokesGetOneTknAfterPutOneTknFirst[0].stateChanges.burns).to.eql([{
assetId: this.lpStableAssetId,
quantity: expectedOutLpAmt,
}]);
expect(invokesGetOneTknAfterPutOneTknFirst.length).to.eql(expectedInvokesCountOldScript);

// putOneTknSecond
// --------------------------------------------------------------------------------------------
await ni.waitForHeight(heightGetOneTknAfterPutOneTknFirst + delay + 1, { apiBase });

const putOneTknSecond = invokeScript({
dApp: lpStable,
@@ -178,9 +159,7 @@ describe('lp_stable_decimals_migration: getOneTkn.mjs', /** @this {MochaSuiteMod
chainId,
}, this.accounts.user1);
await api.transactions.broadcast(putOneTknSecond, {});
const {
height: heightPutOneTknSecond,
} = await ni.waitForTx(putOneTknSecond.id, { apiBase });
await ni.waitForTx(putOneTknSecond.id, { apiBase });

// setScript
// --------------------------------------------------------------------------------------------
@@ -194,7 +173,7 @@ describe('lp_stable_decimals_migration: getOneTkn.mjs', /** @this {MochaSuiteMod
const ssTxLpStableV2 = setScript({
script: base64LpStableV2,
chainId,
fee: 33e5,
fee: 100e5,
senderPublicKey: publicKey(this.accounts.lpStable),
}, this.accounts.manager);
await api.transactions.broadcast(ssTxLpStableV2, {});
@@ -213,7 +192,6 @@ describe('lp_stable_decimals_migration: getOneTkn.mjs', /** @this {MochaSuiteMod

// getOneTknAfterSetScript
// --------------------------------------------------------------------------------------------
await ni.waitForHeight(heightPutOneTknSecond + delay + 1, { apiBase });

const getOneTknAfterSetScript = invokeScript({
dApp: lpStable,
@@ -249,7 +227,7 @@ describe('lp_stable_decimals_migration: getOneTkn.mjs', /** @this {MochaSuiteMod
expect(stateChangesGetOneTknAfterSetScript.data).to.eql([{
key: `%s%s%s__G__${address(this.accounts.user1, chainId)}__${idGetOneTknAfterSetScript}`,
type: 'string',
value: `%d%d%d%d%d%d__${usdtAmount}__${usdnAmount}__${expectedOutLpAmt}__${expectedPriceLast}__${heightGetOneTknAfterSetScript}__${timestampGetOneTknAfterSetScript}`,
value: `%d%d%d%d%d%d__${usdtAmount}__${notUsed}__${expectedOutLpAmt}__${expectedPriceLast}__${heightGetOneTknAfterSetScript}__${timestampGetOneTknAfterSetScript}`,
}, {
key: '%s%s__price__last',
type: 'integer',
@@ -264,26 +242,9 @@ describe('lp_stable_decimals_migration: getOneTkn.mjs', /** @this {MochaSuiteMod
address: address(this.accounts.user1, chainId),
asset: this.usdtAssetId,
amount: usdtAmount,
}, {
address: address(this.accounts.user1, chainId),
asset: this.usdnAssetId,
amount: usdnAmount,
}]);

const { invokes: invokesGetOneTknAfterSetScript } = stateChangesGetOneTknAfterSetScript;
expect(invokesGetOneTknAfterSetScript.length).to.eql(expectedInvokesCount);

expect(invokesGetOneTknAfterSetScript[0].dApp)
.to.eql(address(this.accounts.factoryV2, chainId));
expect(invokesGetOneTknAfterSetScript[0].call.function).to.eql('burn');
expect(invokesGetOneTknAfterSetScript[0].call.args).to.eql([
{
type: 'Int',
value: expectedOutLpAmt,
}]);
expect(invokesGetOneTknAfterSetScript[0].stateChanges.burns).to.eql([{
assetId: this.lpStableAssetId,
quantity: expectedOutLpAmt,
}]);
expect(invokesGetOneTknAfterSetScript.length).to.eql(expectedInvokesCountNewScript);
});
});
Original file line number Diff line number Diff line change
@@ -158,27 +158,6 @@ func setAmp(amp: String) = {
@Callable(i)
func ensureCanGetOneTkn(caller: String) = {
strict checkCaller = i.mustPool()

strict ensureCanPut = match poolContract.getInteger(lastPutOneTknCall(caller)) {
case int: Int => {
let permittedHeight = int + poolContract.getInteger(delay).value()
let isReadyforPutOneTkn = height >= permittedHeight
let needBlocks = permittedHeight - height
isReadyforPutOneTkn || (["you should wait", needBlocks.toString(), "blocks more to perform the action"]).makeString(" ").throw()
}
case _ => true
}

strict ensureCanGet = match poolContract.getInteger(lastGetOneTknCall(caller)) {
case int: Int => {
let permittedHeight = int + poolContract.getInteger(delay).value()
let isReadyforGetOneTkn = height >= permittedHeight
let needBlocks = permittedHeight - height
isReadyforGetOneTkn || (["you should wait", needBlocks.toString(), "blocks more to perform the action"]).makeString(" ").throw()
}
case _ => true
}

strict setI = poolContract.invoke("setI", [lastPutOneTknCall(caller), height], [])

[]
@@ -187,27 +166,6 @@ func ensureCanGetOneTkn(caller: String) = {
@Callable(i)
func ensureCanPutOneTkn(caller: String) = {
strict checkCaller = i.mustPool()

strict ensureCanPut = match poolContract.getInteger(lastPutOneTknCall(caller)) {
case int: Int => {
let permittedHeight = int + poolContract.getInteger(delay).value()
let isReadyforPutOneTkn = height >= permittedHeight
let needBlocks = permittedHeight - height
isReadyforPutOneTkn || (["you should wait", needBlocks.toString(), "blocks more to perform the action"]).makeString(" ").throw()
}
case _ => true
}

strict ensureCanGet = match poolContract.getInteger(lastGetOneTknCall(caller)) {
case int: Int => {
let permittedHeight = int + poolContract.getInteger(delay).value()
let isReadyforGetOneTkn = height >= permittedHeight
let needBlocks = permittedHeight - height
isReadyforGetOneTkn || (["you should wait", needBlocks.toString(), "blocks more to perform the action"]).makeString(" ").throw()
}
case _ => true
}

strict setI = poolContract.invoke("setI", [lastPutOneTknCall(caller), height], [])

[]
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@ describe('lp_stable: getOneTkn.mjs', /** @this {MochaSuiteModified} */() => {

const exchResult = 0;
const notUsed = 0;
const delay = 2;

const expectedOutAmAmt = 1e10;
const expectedOutPrAmt = 0;
@@ -48,9 +47,7 @@ describe('lp_stable: getOneTkn.mjs', /** @this {MochaSuiteModified} */() => {
chainId,
}, this.accounts.user1);
await api.transactions.broadcast(putOneTkn, {});
const { height } = await ni.waitForTx(putOneTkn.id, { apiBase });

await ni.waitForHeight(height + delay, { apiBase });
await ni.waitForTx(putOneTkn.id, { apiBase });

const getOneTkn = invokeScript({
dApp: lpStable,
@@ -101,7 +98,6 @@ describe('lp_stable: getOneTkn.mjs', /** @this {MochaSuiteModified} */() => {

expect(stateChanges.invokes.map((item) => [item.dApp, item.call.function]))
.to.deep.include.members([
[address(this.accounts.lpStableAddon, chainId), 'ensureCanGetOneTkn'],
[address(this.accounts.gwxReward, chainId), 'calcD'],
[address(this.accounts.gwxReward, chainId), 'calcD'],
[address(this.accounts.factoryV2, chainId), 'burn'],
Original file line number Diff line number Diff line change
@@ -77,7 +77,6 @@ describe('lp_stable: putOneTkn.mjs', /** @this {MochaSuiteModified} */() => {

expect(stateChanges.invokes.map((item) => [item.dApp, item.call.function]))
.to.deep.include.members([
[address(this.accounts.lpStableAddon, chainId), 'ensureCanPutOneTkn'],
[address(this.accounts.gwxReward, chainId), 'calcD'],
[address(this.accounts.gwxReward, chainId), 'calcD'],
[address(this.accounts.factoryV2, chainId), 'emit'],
1 change: 0 additions & 1 deletion test/lp_stable/putOneTkn.mjs
Original file line number Diff line number Diff line change
@@ -77,7 +77,6 @@ describe('lp_stable: putOneTkn.mjs', /** @this {MochaSuiteModified} */() => {

expect(stateChanges.invokes.map((item) => [item.dApp, item.call.function]))
.to.deep.include.members([
[address(this.accounts.lpStableAddon, chainId), 'ensureCanPutOneTkn'],
[address(this.accounts.gwxReward, chainId), 'calcD'],
[address(this.accounts.gwxReward, chainId), 'calcD'],
[address(this.accounts.factoryV2, chainId), 'emit'],
1 change: 0 additions & 1 deletion test/lp_stable/putOneTknAutoStake.mjs
Original file line number Diff line number Diff line change
@@ -71,7 +71,6 @@ describe('lp_stable: putOneTkn.mjs', /** @this {MochaSuiteModified} */() => {

expect(stateChanges.invokes.map((item) => [item.dApp, item.call.function]))
.to.deep.include.members([
[address(this.accounts.lpStableAddon, chainId), 'ensureCanPutOneTkn'],
[address(this.accounts.gwxReward, chainId), 'calcD'],
[address(this.accounts.gwxReward, chainId), 'calcD'],
[address(this.accounts.factoryV2, chainId), 'emit'],

0 comments on commit f5e0d4b

Please sign in to comment.