Skip to content

Commit 58f3e6e

Browse files
committed
No longer seed MockNetworkProvider with any test UTXOs
1 parent 41c8eec commit 58f3e6e

5 files changed

Lines changed: 93 additions & 14 deletions

File tree

packages/cashscript/src/network/MockNetworkProvider.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@ import { binToHex, decodeTransactionUnsafe, hexToBin, isHex } from '@bitauth/lib
22
import { sha256 } from '@cashscript/utils';
33
import { Utxo, Network } from '../interfaces.js';
44
import NetworkProvider from './NetworkProvider.js';
5-
import { addressToLockScript, libauthTokenDetailsToCashScriptTokenDetails, randomUtxo } from '../utils.js';
6-
7-
// redeclare the addresses from vars.ts instead of importing them
8-
const aliceAddress = 'bchtest:qpgjmwev3spwlwkgmyjrr2s2cvlkkzlewq62mzgjnp';
9-
const bobAddress = 'bchtest:qz6q5gqnxdldkr07xpls5474mmzmlesd6qnux4skuc';
10-
const carolAddress = 'bchtest:qqsr7nqwe6rq5crj63gy5gdqchpnwmguusmr7tfmsj';
5+
import { addressToLockScript, libauthTokenDetailsToCashScriptTokenDetails } from '../utils.js';
116

127
interface MockNetworkProviderOptions {
138
updateUtxoSet: boolean;
@@ -23,13 +18,6 @@ export default class MockNetworkProvider implements NetworkProvider {
2318

2419
constructor(options?: Partial<MockNetworkProviderOptions>) {
2520
this.options = { updateUtxoSet: true, ...options };
26-
27-
for (let i = 0; i < 3; i += 1) {
28-
// TODO: Don't seed the MockNetworkProvider with any UTXOs
29-
this.addUtxo(aliceAddress, randomUtxo());
30-
this.addUtxo(bobAddress, randomUtxo());
31-
this.addUtxo(carolAddress, randomUtxo());
32-
}
3321
}
3422

3523
async getUtxos(address: string): Promise<Utxo[]> {

packages/cashscript/test/TransactionBuilder.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ describe('Transaction Builder', () => {
3939
(provider as any).addUtxo?.(p2pkhInstance.address, randomUtxo({ token: randomToken() }));
4040
(provider as any).addUtxo?.(twtInstance.address, randomUtxo());
4141
(provider as any).addUtxo?.(twtInstance.address, randomUtxo());
42+
(provider as any).addUtxo?.(aliceAddress, randomUtxo());
43+
(provider as any).addUtxo?.(aliceAddress, randomUtxo());
4244
(provider as any).addUtxo?.(bobAddress, randomUtxo());
4345
(provider as any).addUtxo?.(bobAddress, randomUtxo());
4446
(provider as any).addUtxo?.(carolAddress, randomUtxo());
@@ -206,7 +208,7 @@ describe('Transaction Builder', () => {
206208
const aliceUtxos = (await provider.getUtxos(aliceAddress)).filter(isNonTokenUtxo);
207209
const sigTemplate = new SignatureTemplate(alicePriv);
208210

209-
expect(aliceUtxos.length).toBeGreaterThan(2);
211+
expect(aliceUtxos.length).toBe(2);
210212

211213
const change = aliceUtxos[0].satoshis + aliceUtxos[1].satoshis - 1000n;
212214

packages/cashscript/test/debugging.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,8 @@ describe('Debugging tests', () => {
624624
describe('P2PKH only transaction', () => {
625625
it('should succeed when spending from P2PKH inputs with the corresponding unlocker', async () => {
626626
const provider = new MockNetworkProvider();
627+
provider.addUtxo(aliceAddress, randomUtxo());
628+
provider.addUtxo(aliceAddress, randomUtxo());
627629

628630
const result = new TransactionBuilder({ provider })
629631
.addInputs(await provider.getUtxos(aliceAddress), new SignatureTemplate(alicePriv).unlockP2PKH())
@@ -637,6 +639,8 @@ describe('Debugging tests', () => {
637639
// Note: that also goes for Contract UTXOs where a user uses an unlocker of a different contract
638640
it.skip('should fail when spending from P2PKH inputs with an unlocker for a different public key', async () => {
639641
const provider = new MockNetworkProvider();
642+
provider.addUtxo(aliceAddress, randomUtxo());
643+
provider.addUtxo(aliceAddress, randomUtxo());
640644

641645
const transactionBuilder = new TransactionBuilder({ provider })
642646
.addInputs(await provider.getUtxos(aliceAddress), new SignatureTemplate(bobPriv).unlockP2PKH())

packages/cashscript/test/fixture/libauth-template/multi-contract-fixtures.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,10 @@ export const fixtures: Fixture[] = [
485485
},
486486
},
487487
},
488+
'token': {
489+
'amount': '100000000',
490+
'category': expect.stringMatching(/^[0-9a-f]{64}$/),
491+
},
488492
'valueSatoshis': expect.any(Number),
489493
},
490494
{
@@ -497,6 +501,14 @@ export const fixtures: Fixture[] = [
497501
},
498502
},
499503
},
504+
'token': {
505+
'amount': '0',
506+
'category': expect.stringMatching(/^[0-9a-f]{64}$/),
507+
'nft': {
508+
'capability': 'minting',
509+
'commitment': '00',
510+
},
511+
},
500512
'valueSatoshis': expect.any(Number),
501513
},
502514
{
@@ -723,6 +735,10 @@ export const fixtures: Fixture[] = [
723735
'lockingBytecode': [
724736
'slot',
725737
],
738+
'token': {
739+
'amount': '100000000',
740+
'category': expect.stringMatching(/^[0-9a-f]{64}$/),
741+
},
726742
'valueSatoshis': expect.any(Number),
727743
},
728744
{
@@ -735,6 +751,14 @@ export const fixtures: Fixture[] = [
735751
},
736752
},
737753
},
754+
'token': {
755+
'amount': '0',
756+
'category': expect.stringMatching(/^[0-9a-f]{64}$/),
757+
'nft': {
758+
'capability': 'minting',
759+
'commitment': '00',
760+
},
761+
},
738762
'valueSatoshis': expect.any(Number),
739763
},
740764
{
@@ -967,12 +991,24 @@ export const fixtures: Fixture[] = [
967991
},
968992
},
969993
},
994+
'token': {
995+
'amount': '100000000',
996+
'category': expect.stringMatching(/^[0-9a-f]{64}$/),
997+
},
970998
'valueSatoshis': expect.any(Number),
971999
},
9721000
{
9731001
'lockingBytecode': [
9741002
'slot',
9751003
],
1004+
'token': {
1005+
'amount': '0',
1006+
'category': expect.stringMatching(/^[0-9a-f]{64}$/),
1007+
'nft': {
1008+
'capability': 'minting',
1009+
'commitment': '00',
1010+
},
1011+
},
9761012
'valueSatoshis': expect.any(Number),
9771013
},
9781014
{
@@ -1205,6 +1241,10 @@ export const fixtures: Fixture[] = [
12051241
},
12061242
},
12071243
},
1244+
'token': {
1245+
'amount': '100000000',
1246+
'category': expect.stringMatching(/^[0-9a-f]{64}$/),
1247+
},
12081248
'valueSatoshis': expect.any(Number),
12091249
},
12101250
{
@@ -1217,6 +1257,14 @@ export const fixtures: Fixture[] = [
12171257
},
12181258
},
12191259
},
1260+
'token': {
1261+
'amount': '0',
1262+
'category': expect.stringMatching(/^[0-9a-f]{64}$/),
1263+
'nft': {
1264+
'capability': 'minting',
1265+
'commitment': '00',
1266+
},
1267+
},
12201268
'valueSatoshis': expect.any(Number),
12211269
},
12221270
{
@@ -1444,6 +1492,10 @@ export const fixtures: Fixture[] = [
14441492
},
14451493
},
14461494
},
1495+
'token': {
1496+
'amount': '100000000',
1497+
'category': expect.stringMatching(/^[0-9a-f]{64}$/),
1498+
},
14471499
'valueSatoshis': expect.any(Number),
14481500
},
14491501
{
@@ -1456,6 +1508,14 @@ export const fixtures: Fixture[] = [
14561508
},
14571509
},
14581510
},
1511+
'token': {
1512+
'amount': '0',
1513+
'category': expect.stringMatching(/^[0-9a-f]{64}$/),
1514+
'nft': {
1515+
'capability': 'minting',
1516+
'commitment': '00',
1517+
},
1518+
},
14591519
'valueSatoshis': expect.any(Number),
14601520
},
14611521
{
@@ -1683,6 +1743,10 @@ export const fixtures: Fixture[] = [
16831743
},
16841744
},
16851745
},
1746+
'token': {
1747+
'amount': '100000000',
1748+
'category': expect.stringMatching(/^[0-9a-f]{64}$/),
1749+
},
16861750
'valueSatoshis': expect.any(Number),
16871751
},
16881752
{
@@ -1695,6 +1759,14 @@ export const fixtures: Fixture[] = [
16951759
},
16961760
},
16971761
},
1762+
'token': {
1763+
'amount': '0',
1764+
'category': expect.stringMatching(/^[0-9a-f]{64}$/),
1765+
'nft': {
1766+
'capability': 'minting',
1767+
'commitment': '00',
1768+
},
1769+
},
16981770
'valueSatoshis': expect.any(Number),
16991771
},
17001772
{
@@ -1922,6 +1994,10 @@ export const fixtures: Fixture[] = [
19221994
},
19231995
},
19241996
},
1997+
'token': {
1998+
'amount': '100000000',
1999+
'category': expect.stringMatching(/^[0-9a-f]{64}$/),
2000+
},
19252001
'valueSatoshis': expect.any(Number),
19262002
},
19272003
{
@@ -1934,6 +2010,14 @@ export const fixtures: Fixture[] = [
19342010
},
19352011
},
19362012
},
2013+
'token': {
2014+
'amount': '0',
2015+
'category': expect.stringMatching(/^[0-9a-f]{64}$/),
2016+
'nft': {
2017+
'capability': 'minting',
2018+
'commitment': '00',
2019+
},
2020+
},
19372021
'valueSatoshis': expect.any(Number),
19382022
},
19392023
{

website/docs/releases/release-notes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ title: Release Notes
88
- :boom: **BREAKING**: Set `updateUtxoSet` to `true` by default for `MockNetworkProvider`.
99
- :boom: **BREAKING**: Make `provider` a required option in `Contract` constructor.
1010
- :boom: **BREAKING**: Remove deprecated "old" transaction builder (`contract.functions`).
11+
- :boom: **BREAKING**: No longer seed the MockNetworkProvider with any test UTXOs.
1112
- :hammer_and_wrench: Improve libauth template generation.
1213

1314
## v0.11.5

0 commit comments

Comments
 (0)