@@ -26,10 +26,14 @@ describe('OLAS e2e tests', () => {
26
26
const OLAS_MARKETPLACE_ADDRESS : string = process . env . OLAS_MARKETPLACE_ADDRESS || ZeroAddress
27
27
const TOKEN_ADDRESS : string = process . env . TOKEN_ADDRESS || ZeroAddress
28
28
29
+ let IS_NATIVE_TOKEN = false
30
+
29
31
// 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
33
37
let AMOUNT_TOTAL : bigint
34
38
35
39
let RECEIVER_NVM_FEE : string
@@ -52,8 +56,8 @@ describe('OLAS e2e tests', () => {
52
56
53
57
// Configuration of First Sale:
54
58
// Editor -> Subscriber, the Reseller get a cut (25%)
55
- let amounts : bigint [ ] = [ ]
56
- let receivers : string [ ] = [ ]
59
+ // let amounts: bigint[] = []
60
+ // let receivers: string[] = []
57
61
let planPrice : AssetPrice
58
62
// let royaltyAttributes: RoyaltyAttributes
59
63
@@ -75,7 +79,7 @@ describe('OLAS e2e tests', () => {
75
79
TestContractHandler . setConfig ( config )
76
80
77
81
nevermined = await Nevermined . getInstance ( config )
78
- ; [ , publisher , subscriber ] = nevermined . accounts . list ( )
82
+ ; [ publisher , subscriber ] = nevermined . accounts . list ( )
79
83
80
84
const clientAssertion = await nevermined . utils . jwt . generateClientAssertion ( publisher )
81
85
await nevermined . services . marketplace . login ( clientAssertion )
@@ -90,8 +94,10 @@ describe('OLAS e2e tests', () => {
90
94
91
95
// components
92
96
// ;({ 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 ( ) } ` )
95
101
96
102
// scale = 10n ** BigInt(await token.decimals())
97
103
@@ -100,29 +106,54 @@ describe('OLAS e2e tests', () => {
100
106
// receivers = [publisher.getId(), reseller.getId()]
101
107
102
108
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 ) } ` )
115
132
116
133
AMOUNT_TOTAL = planPrice . getTotalPrice ( )
117
134
// 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
+ }
124
156
}
125
-
126
157
console . log ( `Initial Balances: ${ JSON . stringify ( initialBalances , jsonReplacer ) } ` )
127
158
console . log ( `Asset Price: ${ JSON . stringify ( planPrice , jsonReplacer ) } ` )
128
159
} )
@@ -221,9 +252,15 @@ describe('OLAS e2e tests', () => {
221
252
222
253
assert . isDefined ( agreementId )
223
254
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
+ }
227
264
} )
228
265
229
266
it ( 'The credits seller can check the payment and transfer the NFT to the subscriber' , async ( ) => {
@@ -275,10 +312,15 @@ describe('OLAS e2e tests', () => {
275
312
} )
276
313
277
314
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
+
279
321
console . log ( `OLAS Marketplace Token Balance: ${ tokenBalance } ` )
280
322
console . log ( 'Initial Balances: ' , initialBalances )
281
- console . log ( 'Amounts OLAS FEE: ' , AMOUNT_OLAS_FEE )
323
+ console . log ( 'Amounts OLAS FEE: ' , PLAN_FEE_MKT )
282
324
283
325
assert . isTrue ( tokenBalance > initialBalances . olas )
284
326
} )
0 commit comments