Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 62 additions & 46 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/dapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"jayson": "^4.1.0",
"lodash": "^4.17.21",
"lru-cache": "^5.1.1",
"pino": "^8.16.2",
"pino": "^9.13.0",
"pino-pretty": "^10.2.3",
"ws": "^8.17.1"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/dashmate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"chalk": "^4.1.0",
"cron": "^2.1.0",
"diskusage-ng": "^1.0.4",
"dockerode": "^4.0.5",
"dockerode": "^4.0.9",
"dot": "^1.1.3",
"dotenv": "^8.6.0",
"enquirer": "github:dashpay/enquirer#patch-1",
Expand Down
2 changes: 1 addition & 1 deletion packages/js-evo-sdk/src/contracts/facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class ContractsFacade {
this.sdk = sdk;
}

async fetch(contractId: string): Promise<wasm.DataContractWasm> {
async fetch(contractId: string): Promise<wasm.DataContract> {
const w = await this.sdk.getWasmSdkConnected();
return w.getDataContract(contractId);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/js-evo-sdk/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,4 @@ export { SystemFacade } from './system/facade.js';
export { GroupFacade } from './group/facade.js';
export { VotingFacade } from './voting/facade.js';
export { wallet } from './wallet/functions.js';
export { verifyIdentityResponse, verifyDataContract, verifyDocuments, start } from './wasm.js';
export * from './wasm.js';
4 changes: 2 additions & 2 deletions packages/js-evo-sdk/tests/functional/contracts.spec.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EvoSDK } from '../../dist/evo-sdk.module.js';
import { EvoSDK, DataContract } from '../../dist/evo-sdk.module.js';
import { TEST_IDS } from '../fixtures/testnet.mjs';

describe('Data Contracts', function dataContractsSuite() {
Expand All @@ -13,7 +13,7 @@ describe('Data Contracts', function dataContractsSuite() {

it('fetch() returns data contract', async () => {
const res = await sdk.contracts.fetch(TEST_IDS.dataContractId);
expect(res).to.exist();
expect(res).to.be.instanceOf(DataContract);
});

it('fetchWithProof() returns proof info', async () => {
Expand Down
8 changes: 6 additions & 2 deletions packages/js-evo-sdk/tests/unit/facades/contracts.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ import { EvoSDK } from '../../../dist/sdk.js';
describe('ContractsFacade', () => {
let wasmSdk;
let client;
let dataContract;

beforeEach(async function setup() {
await init();
const builder = wasmSDKPackage.WasmSdkBuilder.testnetTrusted();
wasmSdk = builder.build();
client = EvoSDK.fromWasm(wasmSdk);

dataContract = Object.create(wasmSDKPackage.DataContract.prototype);

// instance methods used by ContractsFacade
this.sinon.stub(wasmSdk, 'getDataContract').resolves(true);
this.sinon.stub(wasmSdk, 'getDataContract').resolves(dataContract);
this.sinon.stub(wasmSdk, 'getDataContractWithProofInfo').resolves(true);
this.sinon.stub(wasmSdk, 'getDataContractHistory').resolves(true);
this.sinon.stub(wasmSdk, 'getDataContractHistoryWithProofInfo').resolves(true);
Expand All @@ -23,8 +26,9 @@ describe('ContractsFacade', () => {
});

it('fetch() forwards to instance getDataContract', async () => {
await client.contracts.fetch('c');
const result = await client.contracts.fetch('c');
expect(wasmSdk.getDataContract).to.be.calledOnceWithExactly('c');
expect(result).to.be.instanceOf(wasmSDKPackage.DataContract);
});

it('fetchWithProof() forwards to instance getDataContractWithProofInfo', async () => {
Expand Down
29 changes: 27 additions & 2 deletions packages/wasm-sdk/src/dpp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ impl IdentityWasm {
// }
// }

#[wasm_bindgen]
#[wasm_bindgen(js_name=DataContract)]
pub struct DataContractWasm(DataContract);

impl From<DataContract> for DataContractWasm {
Expand All @@ -303,12 +303,37 @@ impl From<DataContract> for DataContractWasm {
}
}

#[wasm_bindgen]
#[wasm_bindgen(js_class=DataContract)]
impl DataContractWasm {
pub fn id(&self) -> String {
self.0.id().to_string(Encoding::Base58)
}

#[wasm_bindgen(js_name=fromJSON)]
pub fn from_json(
json: &JsValue,
platform_version: u32,
) -> Result<DataContractWasm, WasmSdkError> {
let platform_version = &PlatformVersion::get(platform_version).map_err(|e| {
WasmSdkError::invalid_argument(format!(
"unknown platform version {platform_version}: {e}"
))
})?;

let data_contract = DataContract::from_json(
serde_wasm_bindgen::from_value(json.clone()).map_err(|e| {
WasmSdkError::serialization(format!("failed to convert json: {}", e))
})?,
true,
platform_version,
)
.map_err(|e| {
WasmSdkError::serialization(format!("failed to create DataContract from json: {}", e))
})?;

Ok(data_contract.into())
}

#[wasm_bindgen(js_name=toJSON)]
pub fn to_json(&self) -> Result<JsValue, WasmSdkError> {
let platform_version = PlatformVersion::first();
Expand Down
23 changes: 23 additions & 0 deletions packages/wasm-sdk/tests/unit/data-contract.spec.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import init, * as sdk from '../../dist/sdk.compressed.js';
import contractFixture from './fixtures/data-contract-crypto-card-game.mjs';

const PLATFORM_VERSION = 1;

describe('DataContract', () => {
before(async () => {
await init();
});

it('should create a contract from JSON and expose identifiers', async () => {
const contract = sdk.DataContract.fromJSON(contractFixture, PLATFORM_VERSION);

expect(contract).to.be.ok();
expect(contract.id()).to.equal(contractFixture.id);

const roundTripped = contract.toJSON();
expect(roundTripped).to.be.an('object');
expect(roundTripped.id).to.equal(contractFixture.id);

contract.free();
});
});
Loading
Loading