5
5
6
6
/* eslint-disable import/order -- https://github.com/endojs/endo/issues/1235 */
7
7
import { test as anyTest } from './prepare-test-env-ava.js' ;
8
-
8
+ import buildZoeManualTimer from '@agoric/zoe/tools/manualTimer.js' ;
9
9
import { createRequire } from 'module' ;
10
10
import { E , Far } from '@endo/far' ;
11
11
import { makePromiseKit } from '@endo/promise-kit' ;
@@ -62,7 +62,12 @@ test('Start the contract', async t => {
62
62
63
63
const money = makeIssuerKit ( 'PlayMoney' ) ;
64
64
const issuers = { Price : money . issuer } ;
65
- const terms = { subscriptionPrice : AmountMath . make ( money . brand , 500n ) } ;
65
+ const timer = buildZoeManualTimer ( ) ;
66
+ const terms = {
67
+ subscriptionPrice : AmountMath . make ( money . brand , 10000000n ) ,
68
+ timerService : timer ,
69
+ } ;
70
+
66
71
t . log ( 'terms:' , terms ) ;
67
72
68
73
/** @type {ERef<Installation<AssetContractFn>> } */
@@ -77,17 +82,20 @@ test('Start the contract', async t => {
77
82
*
78
83
* @param {import('ava').ExecutionContext } t
79
84
* @param {ZoeService } zoe
80
- * @param {ERef<import('@agoric/zoe/src/zoeService/utils').Instance<AssetContractFn> } instance
85
+ * @param {ERef<import('@agoric/zoe/src/zoeService/utils').Instance<AssetContractFn>> } instance
81
86
* @param {Purse } purse
82
87
*/
83
88
const alice = async ( t , zoe , instance , purse ) => {
84
89
const publicFacet = E ( zoe ) . getPublicFacet ( instance ) ;
85
90
// @ts -expect-error Promise<Instance> seems to work
86
91
const terms = await E ( zoe ) . getTerms ( instance ) ;
87
- const { issuers, brands, subscriptionPrice } = terms ;
92
+ const { issuers, brands, subscriptionPrice, timerService } = terms ;
88
93
89
- const serviceType = 'Netflix'
90
- const choiceBag = makeCopyBag ( [ [ { expiryTime : '123' , serviceType } , 1n ] ] ) ;
94
+ const currentTimeRecord = await E ( timerService ) . getCurrentTimestamp ( ) ;
95
+ const serviceType = 'Netflix' ;
96
+ const choiceBag = makeCopyBag ( [
97
+ [ { serviceStarted : currentTimeRecord , serviceType } , 1n ] ,
98
+ ] ) ;
91
99
92
100
const proposal = {
93
101
give : { Price : subscriptionPrice } ,
@@ -100,35 +108,44 @@ const alice = async (t, zoe, instance, purse) => {
100
108
const toTrade = E ( publicFacet ) . makeTradeInvitation ( ) ;
101
109
102
110
const userAddress = 'agoric123456' ;
103
-
104
- const seat = E ( zoe ) . offer ( toTrade , proposal , { Price : pmt } , { userAddress, serviceType } ) ;
111
+ const seat = E ( zoe ) . offer (
112
+ toTrade ,
113
+ proposal ,
114
+ { Price : pmt } ,
115
+ { userAddress, serviceType } ,
116
+ ) ;
105
117
const items = await E ( seat ) . getPayout ( 'Items' ) ;
106
118
107
119
const actual = await E ( issuers . Item ) . getAmountOf ( items ) ;
108
120
t . log ( 'Alice payout brand' , actual . brand ) ;
109
121
t . log ( 'Alice payout value' , actual . value ) ;
110
122
t . deepEqual ( actual , proposal . want . Items ) ;
111
123
112
- const actualMovies = [ `${ serviceType } _Movie_1` , `${ serviceType } _Movie_2` ]
113
- const subscriptionMovies = await E ( publicFacet ) . getSubscriptionResources ( userAddress )
124
+ const actualMovies = [ `${ serviceType } _Movie_1` , `${ serviceType } _Movie_2` ] ;
125
+ const subscriptionMovies =
126
+ await E ( publicFacet ) . getSubscriptionResources ( userAddress ) ;
114
127
115
- t . deepEqual ( actualMovies , subscriptionMovies )
128
+ t . deepEqual ( actualMovies , subscriptionMovies ) ;
116
129
} ;
117
130
118
131
test ( 'Alice trades: give some play money, want subscription' , async t => {
119
132
const { zoe, bundle } = t . context ;
120
133
121
134
const money = makeIssuerKit ( 'PlayMoney' ) ;
122
135
const issuers = { Price : money . issuer } ;
123
- const terms = { subscriptionPrice : AmountMath . make ( money . brand , 500n ) } ;
136
+ const timer = buildZoeManualTimer ( ) ;
137
+ const terms = {
138
+ subscriptionPrice : AmountMath . make ( money . brand , 10000000n ) ,
139
+ timerService : timer ,
140
+ } ;
124
141
/** @type {ERef<Installation<AssetContractFn>> } */
125
142
const installation = E ( zoe ) . install ( bundle ) ;
126
143
const { instance } = await E ( zoe ) . startInstance ( installation , issuers , terms ) ;
127
144
t . log ( instance ) ;
128
145
t . is ( typeof instance , 'object' ) ;
129
146
130
147
const alicePurse = money . issuer . makeEmptyPurse ( ) ;
131
- const amountOfMoney = AmountMath . make ( money . brand , 500n ) ;
148
+ const amountOfMoney = AmountMath . make ( money . brand , 10000000n ) ;
132
149
const moneyPayment = money . mint . mintPayment ( amountOfMoney ) ;
133
150
alicePurse . deposit ( moneyPayment ) ;
134
151
await alice ( t , zoe , instance , alicePurse ) ;
@@ -146,18 +163,19 @@ test('Trade in IST rather than play money', async t => {
146
163
const installation = E ( zoe ) . install ( bundle ) ;
147
164
const feeIssuer = await E ( zoe ) . getFeeIssuer ( ) ;
148
165
const feeBrand = await E ( feeIssuer ) . getBrand ( ) ;
149
- const subscriptionPrice = AmountMath . make ( feeBrand , 500n ) ;
166
+ const subscriptionPrice = AmountMath . make ( feeBrand , 10000000n ) ;
167
+ const timer = buildZoeManualTimer ( ) ;
150
168
return E ( zoe ) . startInstance (
151
169
installation ,
152
170
{ Price : feeIssuer } ,
153
- { subscriptionPrice } ,
171
+ { subscriptionPrice, timerService : timer } ,
154
172
) ;
155
173
} ;
156
174
157
175
const { zoe, bundle, bundleCache, feeMintAccess } = t . context ;
158
176
const { instance } = await startContract ( { zoe, bundle } ) ;
159
177
const { faucet } = makeStableFaucet ( { bundleCache, feeMintAccess, zoe } ) ;
160
- await alice ( t , zoe , instance , await faucet ( 5n * UNIT6 ) ) ;
178
+ await alice ( t , zoe , instance , await faucet ( 10n * UNIT6 ) ) ;
161
179
} ) ;
162
180
163
181
test ( 'use the code that will go on chain to start the contract' , async t => {
@@ -231,5 +249,5 @@ test('use the code that will go on chain to start the contract', async t => {
231
249
// Now that we have the instance, resume testing as above.
232
250
const { feeMintAccess, bundleCache } = t . context ;
233
251
const { faucet } = makeStableFaucet ( { bundleCache, feeMintAccess, zoe } ) ;
234
- await alice ( t , zoe , instance , await faucet ( 5n * UNIT6 ) ) ;
252
+ await alice ( t , zoe , instance , await faucet ( 10n * UNIT6 ) ) ;
235
253
} ) ;
0 commit comments