fix tests
This commit is contained in:
parent
d2d22f81a1
commit
8e3198f3e7
4 changed files with 20 additions and 21 deletions
|
|
@ -24,10 +24,10 @@ const testSuccessfulExternalPayment = async (T: TestBase) => {
|
|||
T.d("paid 500 sats invoice from user1")
|
||||
const u1 = await T.main.storage.userStorage.GetUser(T.user1.userId)
|
||||
const owner = await T.main.storage.userStorage.GetUser(application.owner.user_id)
|
||||
expect(u1.balance_sats).to.be.equal(1496)
|
||||
T.d("user1 balance is now 1496 (2000 - (500 + 3 fee + 1 routing))")
|
||||
expect(owner.balance_sats).to.be.equal(3)
|
||||
T.d("app balance is 3 sats")
|
||||
expect(u1.balance_sats).to.be.equal(1490)
|
||||
T.d("user1 balance is now 1490 (2000 - (500 + 10fee))")
|
||||
expect(owner.balance_sats).to.be.equal(9)
|
||||
T.d("app balance is 9 sats")
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,10 +23,10 @@ const testSuccessfulInternalPayment = async (T: TestBase) => {
|
|||
const owner = await T.main.storage.userStorage.GetUser(application.owner.user_id)
|
||||
expect(u2.balance_sats).to.be.equal(1000)
|
||||
T.d("user2 balance is 1000")
|
||||
expect(u1.balance_sats).to.be.equal(994)
|
||||
T.d("user1 balance is 994 cuz he paid 6 sats fee")
|
||||
expect(owner.balance_sats).to.be.equal(6)
|
||||
T.d("app balance is 6 sats")
|
||||
expect(u1.balance_sats).to.be.equal(990)
|
||||
T.d("user1 balance is 990 cuz he paid 10 sats fee")
|
||||
expect(owner.balance_sats).to.be.equal(10)
|
||||
T.d("app balance is 10 sats")
|
||||
}
|
||||
|
||||
const testFailedInternalPayment = async (T: TestBase) => {
|
||||
|
|
|
|||
|
|
@ -21,30 +21,30 @@ export default async (T: TestBase) => {
|
|||
|
||||
const testInboundPaymentFromProvider = async (T: TestBase, bootstrapped: Main, bUser: TestUserData) => {
|
||||
T.d("starting testInboundPaymentFromProvider")
|
||||
const invoiceRes = await bootstrapped.appUserManager.NewInvoice({ app_id: bUser.appId, user_id: bUser.userId, app_user_id: bUser.appUserIdentifier }, { amountSats: 2000, memo: "liquidityTest" })
|
||||
const invoiceRes = await bootstrapped.appUserManager.NewInvoice({ app_id: bUser.appId, user_id: bUser.userId, app_user_id: bUser.appUserIdentifier }, { amountSats: 3000, memo: "liquidityTest" })
|
||||
|
||||
await T.externalAccessToOtherLnd.PayInvoice(invoiceRes.invoice, 0, 100, 2000, { from: 'system', useProvider: false })
|
||||
await T.externalAccessToOtherLnd.PayInvoice(invoiceRes.invoice, 0, 100, 3000, { from: 'system', useProvider: false })
|
||||
await new Promise((resolve) => setTimeout(resolve, 200))
|
||||
const userBalance = await bootstrapped.appUserManager.GetUserInfo({ app_id: bUser.appId, user_id: bUser.userId, app_user_id: bUser.appUserIdentifier })
|
||||
T.expect(userBalance.balance).to.equal(2000)
|
||||
T.d("user balance is 2000")
|
||||
T.expect(userBalance.balance).to.equal(3000)
|
||||
T.d("user balance is 3000")
|
||||
const providerBalance = await bootstrapped.liquidityProvider.GetLatestBalance()
|
||||
T.expect(providerBalance).to.equal(2000)
|
||||
T.d("provider balance is 2000")
|
||||
T.expect(providerBalance).to.equal(3000)
|
||||
T.d("provider balance is 3000")
|
||||
T.d("testInboundPaymentFromProvider done")
|
||||
}
|
||||
|
||||
const testOutboundPaymentFromProvider = async (T: TestBase, bootstrapped: Main, bootstrappedUser: TestUserData) => {
|
||||
T.d("starting testOutboundPaymentFromProvider")
|
||||
|
||||
const invoice = await T.externalAccessToOtherLnd.NewInvoice(1000, "", 60 * 60, { from: 'system', useProvider: false })
|
||||
const invoice = await T.externalAccessToOtherLnd.NewInvoice(2000, "", 60 * 60, { from: 'system', useProvider: false })
|
||||
const ctx = { app_id: bootstrappedUser.appId, user_id: bootstrappedUser.userId, app_user_id: bootstrappedUser.appUserIdentifier }
|
||||
const res = await bootstrapped.appUserManager.PayInvoice(ctx, { invoice: invoice.payRequest, amount: 0 })
|
||||
|
||||
const userBalance = await bootstrapped.appUserManager.GetUserInfo(ctx)
|
||||
T.expect(userBalance.balance).to.equal(986) // 2000 - (1000 + 6(x2) + 2)
|
||||
T.expect(userBalance.balance).to.equal(988) // 3000 - (2000 + 12)
|
||||
|
||||
const providerBalance = await bootstrapped.liquidityProvider.GetLatestBalance()
|
||||
T.expect(providerBalance).to.equal(992) // 2000 - (1000 + 6 +2)
|
||||
T.expect(providerBalance).to.equal(998) // 3000 - (2000 + 12)
|
||||
T.d("testOutboundPaymentFromProvider done")
|
||||
}
|
||||
|
|
@ -29,16 +29,15 @@ const testSpamExternalPayment = async (T: TestBase) => {
|
|||
const failedPayments = res.filter(r => !r.success)
|
||||
console.log(failedPayments)
|
||||
failedPayments.forEach(f => expect(f.err).to.be.equal("not enough balance to decrement"))
|
||||
successfulPayments.forEach(s => expect(s.result).to.contain({ amount_paid: 500, network_fee: 1, service_fee: 3 }))
|
||||
successfulPayments.forEach(s => expect(s.result).to.contain({ amount_paid: 500, network_fee: 1, service_fee: 10 }))
|
||||
expect(successfulPayments.length).to.be.equal(3)
|
||||
expect(failedPayments.length).to.be.equal(7)
|
||||
T.d("3 payments succeeded, 7 failed as expected")
|
||||
const u = await T.main.storage.userStorage.GetUser(T.user1.userId)
|
||||
const owner = await T.main.storage.userStorage.GetUser(application.owner.user_id)
|
||||
expect(u.balance_sats).to.be.equal(488)
|
||||
T.d("user1 balance is now 488 (2000 - (500 + 3 fee + 1 routing) * 3)")
|
||||
expect(u.balance_sats).to.be.equal(470)
|
||||
T.d("user1 balance is now 470 (2000 - (500 + 10 fee) * 3)")
|
||||
expect(owner.balance_sats).to.be.equal(9)
|
||||
T.d("app balance is 9 sats")
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue