Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
changing rfqdata fields per spec change. still need to merge schema a…
Browse files Browse the repository at this point in the history
…nd test vector change in tbdex repo and update the tbdex submodule
  • Loading branch information
jiyoonie9 committed Jan 18, 2024
1 parent bf9389d commit 50ac168
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 50 deletions.
37 changes: 20 additions & 17 deletions packages/protocol/src/dev-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,24 +233,27 @@ export class DevTools {
}

return {
offeringId : Resource.generateId('offering'),
payinMethod : {
kind : 'DEBIT_CARD',
paymentDetails : {
'cardNumber' : '1234567890123456',
'expiryDate' : '12/22',
'cardHolderName' : 'Ephraim Bartholomew Winthrop',
'cvv' : '123'
}
},
payoutMethod: {
kind : 'BTC_ADDRESS',
paymentDetails : {
btcAddress: '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa'
}
rfq: {
offeringId : Resource.generateId('offering'),
payinMethod : {
kind : 'DEBIT_CARD',
paymentDetails : {
'cardNumber' : '1234567890123456',
'expiryDate' : '12/22',
'cardHolderName' : 'Ephraim Bartholomew Winthrop',
'cvv' : '123'
}
},
payoutMethod: {
kind : 'BTC_ADDRESS',
paymentDetails : {
btcAddress: '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa'
}
},
payinAmount : '200.00',
claims : [credential]
},
payinAmount : '200.00',
claims : [credential]
replyTo: 'https://tbdex.io/alice/callback'
}
}

Expand Down
10 changes: 5 additions & 5 deletions packages/protocol/src/message-kinds/rfq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,27 +155,27 @@ export class Rfq extends Message<'rfq'> {

/** Offering which Alice would like to get a quote for */
get offeringId() {
return this.data.offeringId
return this.data.rfq.offeringId
}

/** Amount of payin currency you want to spend in order to receive payout currency */
get payinAmount() {
return this.data.payinAmount
return this.data.rfq.payinAmount
}

/** Array of claims that satisfy the respective offering's requiredClaims */
get claims() {
return this.data.claims
return this.data.rfq.claims
}

/** Selected payment method that Alice will use to send the listed payin currency to the PFI. */
get payinMethod() {
return this.data.payinMethod
return this.data.rfq.payinMethod
}

/** Selected payment method that the PFI will use to send the listed payout currency to Alice */
get payoutMethod() {
return this.data.payoutMethod
return this.data.rfq.payoutMethod
}

/**
Expand Down
11 changes: 11 additions & 0 deletions packages/protocol/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,17 @@ export type MessageKinds = {
* @beta
*/
export type RfqData = {
/** Details of an RFQ (Request For Quote) */
rfq: RfqDetails
/** A string containing a valid URI where new messages from the PFI will be sent */
replyTo?: string
}

/**
* Details of an RFQ (Request For Quote)
* @beta
*/
export type RfqDetails = {
/** Offering which Alice would like to get a quote for */
offeringId: string
/** Amount of _payin_ currency alice wants to spend in order to receive payout currency */
Expand Down
70 changes: 42 additions & 28 deletions packages/protocol/tests/rfq.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,20 +159,24 @@ describe('Rfq', () => {
to : 'did:ex:pfi'
},
data: {
...await DevTools.createRfqData(),
offeringId: offering.id,
rfq: {
...(await DevTools.createRfqData()).rfq,
offeringId: offering.id
}
}
}
rfqOptions.metadata.from = did.did
rfqOptions.data.claims = [signedCredential]
rfqOptions.data.rfq.claims = [signedCredential]
})

it('throws an error if offeringId doesn\'t match the provided offering\'s id', async () => {
const rfq = Rfq.create({
...rfqOptions,
data: {
...rfqOptions.data,
offeringId: 'ABC123456',
rfq: {
...rfqOptions.data.rfq,
offeringId: 'ABC123456',
}
}
})
try {
Expand All @@ -189,9 +193,11 @@ describe('Rfq', () => {
const rfq = Rfq.create({
...rfqOptions,
data: {
...rfqOptions.data,
payinAmount : '99999999999999999.0',
offeringId : offering.id
rfq: {
...rfqOptions.data.rfq,
payinAmount : '99999999999999999.0',
offeringId : offering.id
}
}
})
try {
Expand All @@ -206,10 +212,12 @@ describe('Rfq', () => {
const rfq = Rfq.create({
...rfqOptions,
data: {
...rfqOptions.data,
payinMethod: {
...rfqOptions.data.payinMethod,
kind: 'POKEMON'
rfq: {
...rfqOptions.data.rfq,
payinMethod: {
...rfqOptions.data.rfq.payinMethod,
kind: 'POKEMON'
}
}
}
})
Expand All @@ -225,11 +233,13 @@ describe('Rfq', () => {
const rfq = Rfq.create({
...rfqOptions,
data: {
...rfqOptions.data,
payinMethod: {
...rfqOptions.data.payinMethod,
paymentDetails: {
beep: 'boop'
rfq: {
...rfqOptions.data.rfq,
payinMethod: {
...rfqOptions.data.rfq.payinMethod,
paymentDetails: {
beep: 'boop'
}
}
}
}
Expand All @@ -246,10 +256,12 @@ describe('Rfq', () => {
const rfq = Rfq.create({
...rfqOptions,
data: {
...rfqOptions.data,
payoutMethod: {
...rfqOptions.data.payoutMethod,
kind: 'POKEMON'
rfq: {
...rfqOptions.data.rfq,
payoutMethod: {
...rfqOptions.data.rfq.payoutMethod,
kind: 'POKEMON'
}
}
}
})
Expand All @@ -265,11 +277,13 @@ describe('Rfq', () => {
const rfq = Rfq.create({
...rfqOptions,
data: {
...rfqOptions.data,
payoutMethod: {
...rfqOptions.data.payoutMethod,
paymentDetails: {
beep: 'boop'
rfq: {
...rfqOptions.data.rfq,
payoutMethod: {
...rfqOptions.data.rfq.payoutMethod,
paymentDetails: {
beep: 'boop'
}
}
}
}
Expand Down Expand Up @@ -297,7 +311,7 @@ describe('Rfq', () => {
})

const rfqData = await DevTools.createRfqData()
rfqData.claims = [signedCredential]
rfqData.rfq.claims = [signedCredential]

const rfq = Rfq.create({
metadata : { from: did.did, to: 'did:ex:pfi' },
Expand All @@ -320,7 +334,7 @@ describe('Rfq', () => {
})

const rfqData = await DevTools.createRfqData()
rfqData.claims = [signedCredential]
rfqData.rfq.claims = [signedCredential]

const rfq = Rfq.create({
metadata : { from: did.did, to: 'did:ex:pfi' },
Expand Down

0 comments on commit 50ac168

Please sign in to comment.