Skip to content

Commit 43a8ce9

Browse files
committed
test: e2e testing
1 parent 7b3e60a commit 43a8ce9

File tree

1 file changed

+74
-32
lines changed

1 file changed

+74
-32
lines changed

integration/external/Olas.e2e.test.ts

Lines changed: 74 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@ describe('OLAS e2e tests', () => {
2626
const OLAS_MARKETPLACE_ADDRESS: string = process.env.OLAS_MARKETPLACE_ADDRESS || ZeroAddress
2727
const TOKEN_ADDRESS: string = process.env.TOKEN_ADDRESS || ZeroAddress
2828

29+
let IS_NATIVE_TOKEN = false
30+
2931
// 10000
30-
let AMOUNT_NVM_FEE: bigint
31-
const AMOUNT_OLAS_FEE = 400n
32-
const AMOUNT_PLAN_PRICE = 9600n
32+
// const AMOUNT_OLAS_FEE = 10000n
33+
// const AMOUNT_PLAN_PRICE = 98000n
34+
let PLAN_FEE_NVM: bigint
35+
let PLAN_FEE_MKT: bigint
36+
let PLAN_PRICE_MECHS: bigint
3337
let AMOUNT_TOTAL: bigint
3438

3539
let RECEIVER_NVM_FEE: string
@@ -52,8 +56,8 @@ describe('OLAS e2e tests', () => {
5256

5357
// Configuration of First Sale:
5458
// Editor -> Subscriber, the Reseller get a cut (25%)
55-
let amounts: bigint[] = []
56-
let receivers: string[] = []
59+
// let amounts: bigint[] = []
60+
// let receivers: string[] = []
5761
let planPrice: AssetPrice
5862
// let royaltyAttributes: RoyaltyAttributes
5963

@@ -75,7 +79,7 @@ describe('OLAS e2e tests', () => {
7579
TestContractHandler.setConfig(config)
7680

7781
nevermined = await Nevermined.getInstance(config)
78-
;[, publisher, subscriber] = nevermined.accounts.list()
82+
;[publisher, subscriber] = nevermined.accounts.list()
7983

8084
const clientAssertion = await nevermined.utils.jwt.generateClientAssertion(publisher)
8185
await nevermined.services.marketplace.login(clientAssertion)
@@ -90,8 +94,10 @@ describe('OLAS e2e tests', () => {
9094

9195
// components
9296
// ;({ token } = nevermined.keeper)
93-
token = await nevermined.contracts.loadErc20(TOKEN_ADDRESS)
94-
console.log(`Using Token Address: ${token.address}`)
97+
98+
console.log(`Using Token Address: ${TOKEN_ADDRESS}`)
99+
console.log(`Publisher: ${publisher.getId()}`)
100+
console.log(`Subscriber: ${subscriber.getId()}`)
95101

96102
// scale = 10n ** BigInt(await token.decimals())
97103

@@ -100,29 +106,54 @@ describe('OLAS e2e tests', () => {
100106
// receivers = [publisher.getId(), reseller.getId()]
101107

102108
RECEIVER_NVM_FEE = await nevermined.keeper.nvmConfig.getFeeReceiver()
103-
AMOUNT_NVM_FEE = await nevermined.keeper.nvmConfig.getNetworkFee()
104-
receivers = [RECEIVER_OLAS_FEE, RECEIVER_PLAN]
105-
amounts = [AMOUNT_OLAS_FEE, AMOUNT_PLAN_PRICE]
106-
107-
planPrice = new AssetPrice(
108-
new Map([
109-
[receivers[0], amounts[0]],
110-
[receivers[1], amounts[1]],
111-
]),
112-
)
113-
.setTokenAddress(TOKEN_ADDRESS)
114-
.adjustToIncludeNetworkFees(RECEIVER_NVM_FEE, AMOUNT_NVM_FEE)
109+
// AMOUNT_NVM_FEE = await nevermined.keeper.nvmConfig.getNetworkFee()
110+
// receivers = [RECEIVER_OLAS_FEE, RECEIVER_PLAN]
111+
// amounts = [PLAN_FEE_MKT, PLAN_PRICE_MECHS]
112+
113+
PLAN_FEE_NVM = BigInt(process.env.PLAN_FEE_NVM || '0')
114+
PLAN_FEE_MKT = BigInt(process.env.PLAN_FEE_MKT || '0')
115+
PLAN_PRICE_MECHS = BigInt(process.env.PLAN_PRICE_MECHS || '0')
116+
117+
console.log(`PLAN_FEES: ${PLAN_FEE_NVM} - ${PLAN_FEE_MKT} - ${PLAN_PRICE_MECHS}`)
118+
119+
const distPayments = new Map()
120+
if (PLAN_FEE_NVM > 0n) distPayments.set(RECEIVER_NVM_FEE, PLAN_FEE_NVM)
121+
if (PLAN_FEE_MKT > 0n) distPayments.set(RECEIVER_OLAS_FEE, PLAN_FEE_MKT)
122+
if (PLAN_PRICE_MECHS > 0n) distPayments.set(RECEIVER_PLAN, PLAN_PRICE_MECHS)
123+
124+
console.log(distPayments)
125+
assert.isTrue(distPayments.size > 0)
126+
127+
planPrice = new AssetPrice(distPayments).setTokenAddress(TOKEN_ADDRESS)
128+
// .adjustToIncludeNetworkFees(RECEIVER_NVM_FEE, AMOUNT_NVM_FEE)
129+
130+
console.log(`Distribution of payments: ${JSON.stringify(distPayments.values(), jsonReplacer)}`)
131+
console.log(`Plan Price: ${JSON.stringify(planPrice, jsonReplacer)}`)
115132

116133
AMOUNT_TOTAL = planPrice.getTotalPrice()
117134
// royaltyAttributes = getRoyaltyAttributes(nevermined, RoyaltyKind.Standard, royalties)
118-
119-
initialBalances = {
120-
publisher: await token.balanceOf(publisher.getId()),
121-
subscriber: await token.balanceOf(subscriber.getId()),
122-
olas: await token.balanceOf(OLAS_MARKETPLACE_ADDRESS),
123-
escrowPaymentCondition: await token.balanceOf(escrowPaymentCondition.address),
135+
IS_NATIVE_TOKEN = TOKEN_ADDRESS === ZeroAddress
136+
137+
if (!IS_NATIVE_TOKEN) {
138+
token = await nevermined.contracts.loadErc20(TOKEN_ADDRESS)
139+
initialBalances = {
140+
publisher: await token.balanceOf(publisher.getId()),
141+
subscriber: await token.balanceOf(subscriber.getId()),
142+
olas: await token.balanceOf(OLAS_MARKETPLACE_ADDRESS),
143+
escrowPaymentCondition: await token.balanceOf(escrowPaymentCondition.address),
144+
}
145+
} else {
146+
initialBalances = {
147+
publisher: await nevermined.client.public.getBalance({ address: publisher.getId() }),
148+
subscriber: await nevermined.client.public.getBalance({ address: subscriber.getId() }),
149+
olas: await nevermined.client.public.getBalance({
150+
address: OLAS_MARKETPLACE_ADDRESS as `0x${string}`,
151+
}),
152+
escrowPaymentCondition: nevermined.client.public.getBalance({
153+
address: escrowPaymentCondition.address,
154+
}),
155+
}
124156
}
125-
126157
console.log(`Initial Balances: ${JSON.stringify(initialBalances, jsonReplacer)}`)
127158
console.log(`Asset Price: ${JSON.stringify(planPrice, jsonReplacer)}`)
128159
})
@@ -221,9 +252,15 @@ describe('OLAS e2e tests', () => {
221252

222253
assert.isDefined(agreementId)
223254
console.debug(`Agreement ID: ${agreementId}`)
224-
const subscriberBalanceAfter = await token.balanceOf(subscriber.getId())
225-
226-
assert.equal(subscriberBalanceAfter, initialBalances.subscriber - AMOUNT_TOTAL)
255+
const subscriberBalanceAfter = IS_NATIVE_TOKEN
256+
? await nevermined.client.public.getBalance({ address: subscriber.getId() })
257+
: await token.balanceOf(subscriber.getId())
258+
259+
if (IS_NATIVE_TOKEN) {
260+
assert.isTrue(subscriberBalanceAfter < initialBalances.subscriber)
261+
} else {
262+
assert.equal(subscriberBalanceAfter, initialBalances.subscriber - AMOUNT_TOTAL)
263+
}
227264
})
228265

229266
it('The credits seller can check the payment and transfer the NFT to the subscriber', async () => {
@@ -275,10 +312,15 @@ describe('OLAS e2e tests', () => {
275312
})
276313

277314
it('the editor and reseller can receive their payment', async () => {
278-
const tokenBalance = await token.balanceOf(OLAS_MARKETPLACE_ADDRESS)
315+
const tokenBalance = IS_NATIVE_TOKEN
316+
? await nevermined.client.public.getBalance({
317+
address: OLAS_MARKETPLACE_ADDRESS as `0x${string}`,
318+
})
319+
: await token.balanceOf(OLAS_MARKETPLACE_ADDRESS)
320+
279321
console.log(`OLAS Marketplace Token Balance: ${tokenBalance}`)
280322
console.log('Initial Balances: ', initialBalances)
281-
console.log('Amounts OLAS FEE: ', AMOUNT_OLAS_FEE)
323+
console.log('Amounts OLAS FEE: ', PLAN_FEE_MKT)
282324

283325
assert.isTrue(tokenBalance > initialBalances.olas)
284326
})

0 commit comments

Comments
 (0)