Skip to content

Commit c7516df

Browse files
fix tests: fix lp_stable_decimals_migration tests
1 parent fbb3aa1 commit c7516df

File tree

2 files changed

+9
-92
lines changed

2 files changed

+9
-92
lines changed

test/lp_stable/lp_stable_decimals_migration/getOneTkn.mjs

Lines changed: 9 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ describe('lp_stable_decimals_migration: getOneTkn.mjs', /** @this {MochaSuiteMod
2626
const autoStake = false;
2727
const usdtAmount = 1e8;
2828
const usdnAmount = 1e8;
29-
const delay = 2;
3029
const exchResult = 0;
3130
const notUsed = 0;
3231

33-
const expectedOutLpAmt = 1e8;
32+
const expectedOutLpAmt = 1e10;
3433
const expectedPriceLast = 5e7;
3534
const expectedPriceHistory = 5e7;
36-
const expectedInvokesCount = 1;
35+
const expectedInvokesCountOldScript = 4;
36+
const expectedInvokesCountNewScript = 3;
3737

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

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

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

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

115113
// check getOneTknAfterPutOneTknFirst
116114
// --------------------------------------------------------------------------------------------
117115
expect(stateChangesGetOneTknAfterPutOneTknFirst.data).to.eql([{
118116
key: `%s%s%s__G__${address(this.accounts.user1, chainId)}__${idGetOneTknAfterPutOneTknFirst}`,
119117
type: 'string',
120-
value: `%d%d%d%d%d%d__${usdtAmount}__${usdnAmount}__${expectedOutLpAmt}__${expectedPriceLast}__${heightGetOneTknAfterPutOneTknFirst}__${timestampGetOneTknAfterPutOneTknFirst}`,
118+
value: `%d%d%d%d%d%d__${usdtAmount}__${notUsed}__${expectedOutLpAmt}__${expectedPriceLast}__${heightGetOneTknAfterPutOneTknFirst}__${timestampGetOneTknAfterPutOneTknFirst}`,
121119
}, {
122120
key: '%s%s__price__last',
123121
type: 'integer',
@@ -132,33 +130,15 @@ describe('lp_stable_decimals_migration: getOneTkn.mjs', /** @this {MochaSuiteMod
132130
address: address(this.accounts.user1, chainId),
133131
asset: this.usdtAssetId,
134132
amount: usdtAmount,
135-
}, {
136-
address: address(this.accounts.user1, chainId),
137-
asset: this.usdnAssetId,
138-
amount: usdnAmount,
139133
}]);
140134

141135
const {
142136
invokes: invokesGetOneTknAfterPutOneTknFirst,
143137
} = stateChangesGetOneTknAfterPutOneTknFirst;
144-
expect(invokesGetOneTknAfterPutOneTknFirst.length).to.eql(expectedInvokesCount);
145-
146-
expect(invokesGetOneTknAfterPutOneTknFirst[0].dApp)
147-
.to.eql(address(this.accounts.factoryV2, chainId));
148-
expect(invokesGetOneTknAfterPutOneTknFirst[0].call.function).to.eql('burn');
149-
expect(invokesGetOneTknAfterPutOneTknFirst[0].call.args).to.eql([
150-
{
151-
type: 'Int',
152-
value: expectedOutLpAmt,
153-
}]);
154-
expect(invokesGetOneTknAfterPutOneTknFirst[0].stateChanges.burns).to.eql([{
155-
assetId: this.lpStableAssetId,
156-
quantity: expectedOutLpAmt,
157-
}]);
138+
expect(invokesGetOneTknAfterPutOneTknFirst.length).to.eql(expectedInvokesCountOldScript);
158139

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

163143
const putOneTknSecond = invokeScript({
164144
dApp: lpStable,
@@ -178,9 +158,6 @@ describe('lp_stable_decimals_migration: getOneTkn.mjs', /** @this {MochaSuiteMod
178158
chainId,
179159
}, this.accounts.user1);
180160
await api.transactions.broadcast(putOneTknSecond, {});
181-
const {
182-
height: heightPutOneTknSecond,
183-
} = await ni.waitForTx(putOneTknSecond.id, { apiBase });
184161

185162
// setScript
186163
// --------------------------------------------------------------------------------------------
@@ -194,7 +171,7 @@ describe('lp_stable_decimals_migration: getOneTkn.mjs', /** @this {MochaSuiteMod
194171
const ssTxLpStableV2 = setScript({
195172
script: base64LpStableV2,
196173
chainId,
197-
fee: 33e5,
174+
fee: 100e5,
198175
senderPublicKey: publicKey(this.accounts.lpStable),
199176
}, this.accounts.manager);
200177
await api.transactions.broadcast(ssTxLpStableV2, {});
@@ -213,7 +190,6 @@ describe('lp_stable_decimals_migration: getOneTkn.mjs', /** @this {MochaSuiteMod
213190

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

218194
const getOneTknAfterSetScript = invokeScript({
219195
dApp: lpStable,
@@ -249,7 +225,7 @@ describe('lp_stable_decimals_migration: getOneTkn.mjs', /** @this {MochaSuiteMod
249225
expect(stateChangesGetOneTknAfterSetScript.data).to.eql([{
250226
key: `%s%s%s__G__${address(this.accounts.user1, chainId)}__${idGetOneTknAfterSetScript}`,
251227
type: 'string',
252-
value: `%d%d%d%d%d%d__${usdtAmount}__${usdnAmount}__${expectedOutLpAmt}__${expectedPriceLast}__${heightGetOneTknAfterSetScript}__${timestampGetOneTknAfterSetScript}`,
228+
value: `%d%d%d%d%d%d__${usdtAmount}__${notUsed}__${expectedOutLpAmt}__${expectedPriceLast}__${heightGetOneTknAfterSetScript}__${timestampGetOneTknAfterSetScript}`,
253229
}, {
254230
key: '%s%s__price__last',
255231
type: 'integer',
@@ -264,26 +240,9 @@ describe('lp_stable_decimals_migration: getOneTkn.mjs', /** @this {MochaSuiteMod
264240
address: address(this.accounts.user1, chainId),
265241
asset: this.usdtAssetId,
266242
amount: usdtAmount,
267-
}, {
268-
address: address(this.accounts.user1, chainId),
269-
asset: this.usdnAssetId,
270-
amount: usdnAmount,
271243
}]);
272244

273245
const { invokes: invokesGetOneTknAfterSetScript } = stateChangesGetOneTknAfterSetScript;
274-
expect(invokesGetOneTknAfterSetScript.length).to.eql(expectedInvokesCount);
275-
276-
expect(invokesGetOneTknAfterSetScript[0].dApp)
277-
.to.eql(address(this.accounts.factoryV2, chainId));
278-
expect(invokesGetOneTknAfterSetScript[0].call.function).to.eql('burn');
279-
expect(invokesGetOneTknAfterSetScript[0].call.args).to.eql([
280-
{
281-
type: 'Int',
282-
value: expectedOutLpAmt,
283-
}]);
284-
expect(invokesGetOneTknAfterSetScript[0].stateChanges.burns).to.eql([{
285-
assetId: this.lpStableAssetId,
286-
quantity: expectedOutLpAmt,
287-
}]);
246+
expect(invokesGetOneTknAfterSetScript.length).to.eql(expectedInvokesCountNewScript);
288247
});
289248
});

test/lp_stable/lp_stable_decimals_migration/ride/lp_stable_addon_old.ride

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -158,27 +158,6 @@ func setAmp(amp: String) = {
158158
@Callable(i)
159159
func ensureCanGetOneTkn(caller: String) = {
160160
strict checkCaller = i.mustPool()
161-
162-
strict ensureCanPut = match poolContract.getInteger(lastPutOneTknCall(caller)) {
163-
case int: Int => {
164-
let permittedHeight = int + poolContract.getInteger(delay).value()
165-
let isReadyforPutOneTkn = height >= permittedHeight
166-
let needBlocks = permittedHeight - height
167-
isReadyforPutOneTkn || (["you should wait", needBlocks.toString(), "blocks more to perform the action"]).makeString(" ").throw()
168-
}
169-
case _ => true
170-
}
171-
172-
strict ensureCanGet = match poolContract.getInteger(lastGetOneTknCall(caller)) {
173-
case int: Int => {
174-
let permittedHeight = int + poolContract.getInteger(delay).value()
175-
let isReadyforGetOneTkn = height >= permittedHeight
176-
let needBlocks = permittedHeight - height
177-
isReadyforGetOneTkn || (["you should wait", needBlocks.toString(), "blocks more to perform the action"]).makeString(" ").throw()
178-
}
179-
case _ => true
180-
}
181-
182161
strict setI = poolContract.invoke("setI", [lastPutOneTknCall(caller), height], [])
183162

184163
[]
@@ -187,27 +166,6 @@ func ensureCanGetOneTkn(caller: String) = {
187166
@Callable(i)
188167
func ensureCanPutOneTkn(caller: String) = {
189168
strict checkCaller = i.mustPool()
190-
191-
strict ensureCanPut = match poolContract.getInteger(lastPutOneTknCall(caller)) {
192-
case int: Int => {
193-
let permittedHeight = int + poolContract.getInteger(delay).value()
194-
let isReadyforPutOneTkn = height >= permittedHeight
195-
let needBlocks = permittedHeight - height
196-
isReadyforPutOneTkn || (["you should wait", needBlocks.toString(), "blocks more to perform the action"]).makeString(" ").throw()
197-
}
198-
case _ => true
199-
}
200-
201-
strict ensureCanGet = match poolContract.getInteger(lastGetOneTknCall(caller)) {
202-
case int: Int => {
203-
let permittedHeight = int + poolContract.getInteger(delay).value()
204-
let isReadyforGetOneTkn = height >= permittedHeight
205-
let needBlocks = permittedHeight - height
206-
isReadyforGetOneTkn || (["you should wait", needBlocks.toString(), "blocks more to perform the action"]).makeString(" ").throw()
207-
}
208-
case _ => true
209-
}
210-
211169
strict setI = poolContract.invoke("setI", [lastPutOneTknCall(caller), height], [])
212170

213171
[]

0 commit comments

Comments
 (0)