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

Commit

Permalink
Bind offering to_json_string, use it to make test pass
Browse files Browse the repository at this point in the history
  • Loading branch information
KendallWeihe committed Sep 23, 2024
1 parent 90eac0d commit 5d38b3a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
6 changes: 5 additions & 1 deletion bindings/tbdex_wasm/src/resources/offering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
web5::presentation_definition::WasmPresentationDefinition,
};
use tbdex::{
json::FromJson,
json::{FromJson, ToJson},
resources::offering::{
CancellationDetails, Offering, OfferingData, PayinDetails, PayinMethod, PayoutDetails,
PayoutMethod,
Expand Down Expand Up @@ -46,6 +46,10 @@ impl WasmOffering {
})
}

pub fn to_json_string(&self) -> Result<String> {
Ok(self.inner.to_json_string().map_err(map_err)?)
}

pub fn verify(&self) -> Result<()> {
self.inner.verify().map_err(map_err)
}
Expand Down
9 changes: 9 additions & 0 deletions bound/typescript/src/resources/offering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ export class Offering {
}
}

toJSONString(): string {
try {
return this.toWASM().to_json_string();
} catch (error) {
throw catchTbdexError(error);
}
}

static create(from: string, data: OfferingData, protocol?: string): Offering {
try {
return Offering.fromWASM(
Expand All @@ -62,6 +70,7 @@ export class Offering {
}
}

// TODO consider using type's instead of class's like we used to
export class OfferingData {
readonly description: string;
readonly payoutUnitsPerPayinUnit: string;
Expand Down
4 changes: 4 additions & 0 deletions bound/typescript/src/wasm/generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,10 @@ export class WasmOffering {
*/
static from_json_string(json: string): WasmOffering;
/**
* @returns {string}
*/
to_json_string(): string;
/**
*/
verify(): void;
/**
Expand Down
5 changes: 4 additions & 1 deletion bound/typescript/tests/test-vectors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ describe("test vectors", () => {
const input = OfferingVector.input;
const offering = Offering.fromJSONString(input);

expect(offering).to.deep.equal(OfferingVector.output);
const offeringJSONString = offering.toJSONString();
const offeringJSON = JSON.parse(offeringJSONString);

expect(offeringJSON).to.deep.equal(OfferingVector.output);

offering.verify();
});
Expand Down

0 comments on commit 5d38b3a

Please sign in to comment.