Skip to content

Commit 9589673

Browse files
committed
Update MockNetworkProvider and its docs
1 parent a9b4062 commit 9589673

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

packages/cashscript/src/network/MockNetworkProvider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ import { addressToLockScript, libauthTokenDetailsToCashScriptTokenDetails } from
66
import { DEFAULT_VM_TARGET } from '../libauth-template/utils.js';
77

88
export interface MockNetworkProviderOptions {
9-
updateUtxoSet: boolean;
9+
updateUtxoSet?: boolean;
1010
vmTarget?: VmTarget;
1111
}
1212

1313
export default class MockNetworkProvider implements NetworkProvider {
1414
// we use lockingBytecode hex as the key for utxoMap to make cash addresses and token addresses interchangeable
1515
private utxoSet: Array<[string, Utxo]> = [];
1616
private transactionMap: Record<string, string> = {};
17+
private blockHeight: number = 133700;
1718
public network: Network = Network.MOCKNET;
18-
public blockHeight: number = 133700;
1919
public options: MockNetworkProviderOptions;
2020
public vmTarget: VmTarget;
2121

website/docs/releases/release-notes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ This release contains several breaking changes, please refer to the [migration n
2323
- :sparkles: Add support for `p2s` contract type.
2424
- :sparkles: Add `lockingBytecode` property to `Contract` class.
2525
- :sparkles: Add `getUtxosForLockingBytecode()` method to `ElectrumNetworkProvider` class and `MockNetworkProvider` interface.
26+
- :sparkles: In the `MockNetworkProvider`, `addUtxo()` now also allows UTXOs to be added by locking bytecode.
2627
- :hammer_and_wrench: **BREAKING**: Rename `addressType` option on `Contract` constructor to `contractType`.
2728
- :hammer_and_wrench: **BREAKING**: Remove undocumented `redeemScript` property from `Contract` class.
2829
- :hammer_and_wrench: Update default VM target to `BCH_2026_05`.

website/docs/sdk/other-network-providers.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,22 @@ interface MockNetworkProviderOptions {
1919
updateUtxoSet?: boolean;
2020
vmTarget?: VmTarget;
2121
}
22+
23+
interface MockNetworkProvider extends NetworkProvider {
24+
options: MockNetworkProviderOptions;
25+
vmTarget: VmTarget;
26+
27+
constructor(options?: Partial<MockNetworkProviderOptions>) {}
28+
29+
// Hardcode the block height
30+
setBlockHeight(newBlockHeight: number): void;
31+
32+
// Add a UTXO to the UTXO set of the mock network
33+
addUtxo(addressOrLockingBytecode: string, utxo: Utxo): void;
34+
35+
// Reset the UTXO set and transaction list of the mock network
36+
reset(): void;
37+
}
2238
```
2339

2440
The `updateUtxoSet` option is used to determine whether the UTXO set should be updated after a transaction is sent. If `updateUtxoSet` is `true` (default), the UTXO set will be updated to reflect the new state of the mock network. If `updateUtxoSet` is `false`, the UTXO set will not be updated.

0 commit comments

Comments
 (0)