From 1dd386a206c259303f2b525054b92d4591fca572 Mon Sep 17 00:00:00 2001 From: Jorge-Lopes Date: Thu, 31 Oct 2024 15:16:05 +0000 Subject: [PATCH] fix(a3p): optimize error messages and reduce logs rel: https://github.com/Agoric/BytePitchPartnerEng/issues/22 --- .../proposals/z:acceptance/vaults.test.js | 99 +++++-------------- 1 file changed, 24 insertions(+), 75 deletions(-) diff --git a/a3p-integration/proposals/z:acceptance/vaults.test.js b/a3p-integration/proposals/z:acceptance/vaults.test.js index a92c5a08d8d6..9eb5e5624034 100644 --- a/a3p-integration/proposals/z:acceptance/vaults.test.js +++ b/a3p-integration/proposals/z:acceptance/vaults.test.js @@ -34,8 +34,6 @@ test.serial('open new vault', async t => { const istBalanceBefore = await getISTBalance(USER1ADDR); const activeVaultsBefore = await agopsVaults(USER1ADDR); - t.log('uist balance before:', istBalanceBefore); - t.log('active vaults before:', activeVaultsBefore); const mint = '5.0'; const collateral = '10.0'; @@ -43,8 +41,6 @@ test.serial('open new vault', async t => { const istBalanceAfter = await getISTBalance(USER1ADDR); const activeVaultsAfter = await agopsVaults(USER1ADDR); - t.log('uist balance after:', istBalanceAfter); - t.log('active vaults after:', activeVaultsAfter); t.is( istBalanceBefore + 5, @@ -62,15 +58,11 @@ test.serial('remove collateral', async t => { const { vaultID, collateral: collateralBefore } = await getLastVaultFromAddress(USER1ADDR); - t.log('vault collateral before:', collateralBefore); - await adjustVault(USER1ADDR, vaultID, { wantCollateral: 1.0 }); const { collateral: collateralAfter } = await getLastVaultFromAddress(USER1ADDR); - t.log('vault collateral after:', collateralAfter); - t.is( collateralBefore, collateralAfter + 1_000_000n, @@ -81,12 +73,10 @@ test.serial('remove collateral', async t => { test.serial('remove IST', async t => { const { vaultID, debt: debtBefore } = await getLastVaultFromAddress(USER1ADDR); - t.log('vault debt before:', debtBefore); await adjustVault(USER1ADDR, vaultID, { wantMinted: 1.0 }); const { debt: debtAfter } = await getLastVaultFromAddress(USER1ADDR); - t.log('vault debt after:', debtAfter); t.is( debtAfter, @@ -98,17 +88,15 @@ test.serial('remove IST', async t => { test.serial('add collateral', async t => { const { vaultID, collateral: collateralBefore } = await getLastVaultFromAddress(USER1ADDR); - t.log('vault collateral before:', collateralBefore); await adjustVault(USER1ADDR, vaultID, { giveCollateral: 1.0 }); const { collateral: collateralAfter } = await getLastVaultFromAddress(USER1ADDR); - t.log('vault collateral after:', collateralAfter); t.is( - collateralBefore, - collateralAfter - 1_000_000n, + collateralAfter, + collateralBefore + 1_000_000n, 'The vault Collateral should increase after adding some ATOM', ); }); @@ -116,12 +104,10 @@ test.serial('add collateral', async t => { test.serial('add IST', async t => { const { vaultID, debt: debtBefore } = await getLastVaultFromAddress(USER1ADDR); - t.log('vault debt before:', debtBefore); await adjustVault(USER1ADDR, vaultID, { giveMinted: 1.0 }); const { debt: debtAfter } = await getLastVaultFromAddress(USER1ADDR); - t.log('vault debt after:', debtAfter); t.is( debtAfter, @@ -132,18 +118,12 @@ test.serial('add IST', async t => { test.serial('close vault', async t => { const { vaultID, collateral } = await getLastVaultFromAddress(USER1ADDR); - t.log('vault collateral:', collateral); - const atomBalanceBefore = await getBalances([USER1ADDR], ATOM_DENOM); - t.log('atom balance before', atomBalanceBefore); await closeVault(USER1ADDR, vaultID, 6.035); const atomBalanceAfter = await getBalances([USER1ADDR], ATOM_DENOM); - t.log('atom balance after', atomBalanceAfter); - const { state } = await getLastVaultFromAddress(USER1ADDR); - t.log('vault state:', state); t.is( atomBalanceAfter, @@ -158,7 +138,6 @@ test.serial( async t => { await bankSend(GOV1ADDR, `200000000000000000${ATOM_DENOM}`); const activeVaultsBefore = await agopsVaults(GOV1ADDR); - t.log('active vaults before:', activeVaultsBefore); const minInitialDebt = await getMinInitialDebt(); @@ -168,14 +147,11 @@ test.serial( await t.throwsAsync( () => openVault(GOV1ADDR, mint.toString(), collateral.toString()), { - message: new RegExp( - `Error: Vault creation requires a minInitialDebt of {"brand":"\\[Alleged: IST brand\\]","value":"\\[${minInitialDebt * 1_000_000n}n\\]"}`, - ), + message: /Error: Vault creation requires a minInitialDebt/, }, ); const activeVaultsAfter = await agopsVaults(GOV1ADDR); - t.log('active vaults after:', activeVaultsAfter); t.is( activeVaultsAfter.length, @@ -187,26 +163,20 @@ test.serial( test.serial('user cannot open a vault above debt limit', async t => { const activeVaultsBefore = await agopsVaults(GOV1ADDR); - t.log('active vaults before:', activeVaultsBefore); - const { availableDebtForMint, debtLimit, totalDebt } = - await getAvailableDebtForMint(VAULT_MANAGER); + const { availableDebtForMint } = await getAvailableDebtForMint(VAULT_MANAGER); const mint = availableDebtForMint + 5n; const collateral = mint * 2n; - const { adjustedToMintAmount } = await calculateMintFee(mint, VAULT_MANAGER); await t.throwsAsync( () => openVault(GOV1ADDR, mint.toString(), collateral.toString()), { - message: new RegExp( - `Minting {"brand":"\\[Alleged: IST brand\\]","value":"\\[${adjustedToMintAmount.value}n\\]"} past {"brand":"\\[Alleged: IST brand\\]","value":"\\[${totalDebt}n\\]"} would hit total debt limit {"brand":"\\[Alleged: IST brand\\]","value":"\\[${debtLimit}n\\]"}`, - ), + message: /Error: Minting.*would hit total debt limit/, }, ); const activeVaultsAfter = await agopsVaults(GOV1ADDR); - t.log('active vaults after:', activeVaultsAfter); t.is( activeVaultsAfter.length, @@ -218,8 +188,6 @@ test.serial('user cannot open a vault above debt limit', async t => { test.serial('user can open a vault under debt limit', async t => { const istBalanceBefore = await getISTBalance(GOV1ADDR); const activeVaultsBefore = await agopsVaults(GOV1ADDR); - t.log('uist balance before:', istBalanceBefore); - t.log('active vaults before:', activeVaultsBefore); const { availableDebtForMint } = await getAvailableDebtForMint(VAULT_MANAGER); @@ -230,8 +198,6 @@ test.serial('user can open a vault under debt limit', async t => { const istBalanceAfter = await getISTBalance(GOV1ADDR); const activeVaultsAfter = await agopsVaults(GOV1ADDR); - t.log('uist balance after:', istBalanceAfter); - t.log('active vaults after:', activeVaultsAfter); t.is( istBalanceBefore + Number(mint), @@ -247,15 +213,8 @@ test.serial('user can open a vault under debt limit', async t => { test.serial('user cannot increased vault debt above debt limit', async t => { const { vaultID, debt: debtBefore } = await getLastVaultFromAddress(GOV1ADDR); - t.log('vault debt before:', debtBefore); - - const { availableDebtForMint, debtLimit, totalDebt } = - await getAvailableDebtForMint(VAULT_MANAGER); - const { adjustedToMintAmount } = await calculateMintFee( - availableDebtForMint, - VAULT_MANAGER, - ); + const { availableDebtForMint } = await getAvailableDebtForMint(VAULT_MANAGER); // The availableDebtForMint + mintFee will surpass the debt limit const mint = Number(availableDebtForMint); @@ -265,14 +224,11 @@ test.serial('user cannot increased vault debt above debt limit', async t => { wantMinted: mint, }), { - message: new RegExp( - `Minting {"brand":"\\[Alleged: IST brand\\]","value":"\\[${adjustedToMintAmount.value}n\\]"} past {"brand":"\\[Alleged: IST brand\\]","value":"\\[${totalDebt}n\\]"} would hit total debt limit {"brand":"\\[Alleged: IST brand\\]","value":"\\[${debtLimit}n\\]"}`, - ), + message: /Error: Minting.*would hit total debt limit/, }, ); const { debt: debtAfter } = await getLastVaultFromAddress(GOV1ADDR); - t.log('vault debt after:', debtAfter); t.is(debtAfter, debtBefore, 'The vault Debt should stay the same'); }); @@ -288,11 +244,9 @@ test.serial( mint, VAULT_MANAGER, ); - t.log('mint + fee:', adjustedToMintAmount.value); const { vaultID, debt: debtAfterOpenVault } = await getLastVaultFromAddress(GOV1ADDR); - t.log('vault debt after open:', debtAfterOpenVault); t.is( debtAfterOpenVault, @@ -304,11 +258,9 @@ test.serial( const { adjustedToMintAmount: adjustedToMintAmountAfter } = await calculateMintFee(1n, VAULT_MANAGER); - t.log('wantMinted + fee:', adjustedToMintAmountAfter.value); const { debt: debtAfterAdjustVault } = await getLastVaultFromAddress(GOV1ADDR); - t.log('vault debt after adjust:', debtAfterAdjustVault); t.is( debtAfterAdjustVault, @@ -335,14 +287,23 @@ test.serial('confirm that Oracle prices are being received', async t => { await verifyPushedPrice(oraclesByBrand, BRANDS[0], 10, roundId); const atomQuote = await getPriceQuote(BRANDS[0]); - t.log('price quote:', atomQuote); - t.is(atomQuote, '+10000000'); + t.is( + atomQuote, + '+10000000', + 'ATOM price quote does not match the expected value', + ); const vaultQuote = await getVaultPrices(ATOMManagerIndex); - t.log('vault quote:', vaultQuote.value[0].amountOut.value); - t.true(vaultQuote.value[0].amountIn.brand.includes(' ATOM ')); - t.is(vaultQuote.value[0].amountOut.value, atomQuote); + t.true( + vaultQuote.value[0].amountIn.brand.includes(' ATOM '), + 'ATOM price quote not found', + ); + t.is( + vaultQuote.value[0].amountOut.value, + atomQuote, + 'Vault price quote does not match the expected ATOM price quote', + ); }); test.serial( @@ -354,18 +315,12 @@ test.serial( */ const user = await getUser('long-living-vault'); - const { - vaultID, - debt: debtAfterOpenVault, - collateral: collateralBefore, - } = await getLastVaultFromAddress(user); - t.log('vault debt after open:', debtAfterOpenVault); - t.log('vault collateral before:', collateralBefore); + const { vaultID, collateral: collateralBefore } = + await getLastVaultFromAddress(user); await adjustVault(user, vaultID, { wantCollateral: 1.0 }); const { collateral: collateralAfter } = await getLastVaultFromAddress(user); - t.log('vault collateral after:', collateralAfter); t.is( collateralBefore, @@ -376,7 +331,6 @@ test.serial( await closeVault(user, vaultID, 6.03); const { state } = await getLastVaultFromAddress(user); - t.log('vault state:', state); t.is(state, 'closed', 'The vault should be in the "closed" state.'); }, @@ -389,17 +343,14 @@ test.serial( const collateral = '10.0'; await openVault(GOV1ADDR, mint, collateral); - const { debtLimit: debtLimitBefore, totalDebt: totalDebtBefore } = + const { totalDebt: totalDebtBefore } = await getAvailableDebtForMint(VAULT_MANAGER); - t.log('debtLimit before adjusting parameter: ', debtLimitBefore); - t.log('totalDebt before adjusting parameter: ', totalDebtBefore); const limit = (totalDebtBefore - 10_000_000n) / 1_000_000n; await setDebtLimit(GOV1ADDR, limit); const { debtLimit: debtLimitAfter, totalDebt: totalDebtAfter } = await getAvailableDebtForMint(VAULT_MANAGER); - t.log('debtLimit after adjusting parameter: ', debtLimitAfter); t.true( debtLimitAfter < totalDebtAfter, 'debtLimit should be less than totalDebt', @@ -407,14 +358,12 @@ test.serial( const { vaultID, debt: vaultDebtBefore } = await getLastVaultFromAddress(GOV1ADDR); - t.log('vault debt before pay off:', vaultDebtBefore); await adjustVault(GOV1ADDR, vaultID, { giveMinted: Number(vaultDebtBefore) / 1_000_000, }); const { debt: vaultDebtAfter } = await getLastVaultFromAddress(GOV1ADDR); - t.log('vault debt after pay off:', vaultDebtAfter); t.is(vaultDebtAfter, 0n, 'The vault Debt should have been erased'); },