Skip to content
This repository was archived by the owner on Feb 27, 2025. It is now read-only.

Commit b8f1bef

Browse files
committed
package json error modified, tests modified
1 parent dc389cb commit b8f1bef

32 files changed

+8127
-5761
lines changed

package-lock.json

+1,427-102
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@
77
"lerna-publish-beta": "lerna publish --no-private --conventional-commits from-git --dist-tag beta"
88
},
99
"devDependencies": {
10-
"@tsconfig/recommended": "^1.0.1"
10+
"@tsconfig/recommended": "^1.0.1",
11+
"raf": "^3.4.1"
1112
},
1213
"dependencies": {
13-
"lerna": "^6.4.0"
14+
"-": "^0.0.1",
15+
"@types/node": "^20.3.1",
16+
"lerna": "^6.4.0",
17+
"raf-polyfill": "^1.0.0",
18+
"save-dev": "^0.0.1-security",
19+
"typescript": "^5.1.3"
1420
},
1521
"workspaces": [
1622
"packages/*"

packages/chains/jest.setup.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const { JSDOM } = require('jsdom')
2+
const React = require('react')
3+
const { useContext } = require('react')
4+
const { render } = require('react-dom')
5+
const { renderHook } = require('@testing-library/react-hooks')
6+
require('raf/polyfill')
7+
8+
const jsdom = new JSDOM('<!doctype html><html><body></body></html>')
9+
10+
global.window = jsdom.window
11+
global.document = jsdom.window.document
12+
global.navigator = {
13+
userAgent: 'node.js',
14+
}
15+
global.React = React
16+
global.useContext = useContext
17+
global.render = render
18+
global.renderHook = renderHook

packages/chains/package.json

+22-3
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,37 @@
88
"repository": "github:esteblock/soroban-react",
99
"version": "5.0.3",
1010
"scripts": {
11-
"prebuild": "rm -rf dist",
12-
"build": "tsc",
13-
"start": "tsc --watch"
11+
"prebuild": "del /s /q dist",
12+
"prebuild-linux": "rd -rf dist",
13+
"build": "yarn prebuild && tsc",
14+
"prepare": "install-peers",
15+
"start": "tsc --watch",
16+
"test": "yarn prepare && yarn build && yarn jest"
1417
},
1518
"main": "dist/index.js",
1619
"exports": "./dist/index.js",
1720
"types": "dist/index.d.ts",
1821
"files": [
1922
"/dist"
2023
],
24+
"jest": {
25+
"setupFilesAfterEnv": [
26+
"./jest.setup.js"
27+
],
28+
"collectCoverage": true
29+
},
2130
"dependencies": {
2231
"@soroban-react/types": "^5.0.3",
2332
"soroban-client": "0.8.0"
33+
},
34+
"devDependencies": {
35+
"@types/jest": "^29.5.2",
36+
"install-peers-cli": "^2.2.0",
37+
"jest": "^29.5.0",
38+
"jsdom": "^22.1.0",
39+
"ts-jest": "^29.1.0"
40+
},
41+
"peerDependencies": {
42+
"react": "^17.0.2"
2443
}
2544
}

packages/chains/tests/index.test.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const {
2+
public_chain,
3+
futurenet,
4+
testnet,
5+
sandbox,
6+
standalone,
7+
} = require('../dist/index.js')
8+
9+
const PUBLIC_PASSPHRASE = 'Public Global Stellar Network ; September 2015'
10+
const TESTNET_PASSPHRASE = 'Test SDF Network ; September 2015'
11+
const FUTURENET_PASSPHRASE = 'Test SDF Future Network ; October 2022'
12+
const SANDBOX_PASSPHRASE = 'Local Sandbox Stellar Network ; September 2022'
13+
const STANDALONE_PASSPHRASE = 'Standalone Network ; February 2017'
14+
15+
describe('Module exports', () => {
16+
test('should export public_chain', () => {
17+
expect(public_chain.id).toEqual('public')
18+
expect(public_chain.name).toEqual('Public')
19+
expect(public_chain.networkPassphrase).toEqual(PUBLIC_PASSPHRASE)
20+
})
21+
22+
test('should export futurenet', () => {
23+
expect(futurenet.id).toEqual('public')
24+
expect(futurenet.name).toEqual('Futurenet')
25+
expect(futurenet.networkPassphrase).toEqual(FUTURENET_PASSPHRASE)
26+
})
27+
28+
test('should export testnet', () => {
29+
expect(testnet.id).toEqual('public')
30+
expect(testnet.name).toEqual('Testnet')
31+
expect(testnet.networkPassphrase).toEqual(TESTNET_PASSPHRASE)
32+
})
33+
34+
test('should export sandbox', () => {
35+
expect(sandbox.id).toEqual('public')
36+
expect(sandbox.name).toEqual('Sandbox')
37+
expect(sandbox.networkPassphrase).toEqual(SANDBOX_PASSPHRASE)
38+
})
39+
40+
test('should export standalone', () => {
41+
expect(standalone.id).toEqual('public')
42+
expect(standalone.name).toEqual('Standalone')
43+
expect(standalone.networkPassphrase).toEqual(STANDALONE_PASSPHRASE)
44+
})
45+
})

packages/connect-button/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"repository": "github:esteblock/soroban-react",
99
"version": "5.0.3",
1010
"scripts": {
11-
"prebuild": "rm -rf dist",
11+
"prebuild": "del /s /q dist",
1212
"build": "tsc",
1313
"start": "tsc --watch"
1414
},

packages/contracts/.babelrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["@babel/preset-react"]
3+
}

packages/contracts/jest.setup.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const { JSDOM } = require('jsdom')
2+
const React = require('react')
3+
const { useContext } = require('react')
4+
const { render } = require('react-dom')
5+
const { renderHook } = require('@testing-library/react-hooks')
6+
require('raf/polyfill')
7+
8+
const jsdom = new JSDOM('<!doctype html><html><body></body></html>')
9+
10+
global.window = jsdom.window
11+
global.document = jsdom.window.document
12+
global.navigator = {
13+
userAgent: 'node.js',
14+
}
15+
global.React = React
16+
global.useContext = useContext
17+
global.render = render
18+
global.renderHook = renderHook

packages/contracts/package.json

+20-4
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,38 @@
88
"repository": "github:esteblock/soroban-react",
99
"version": "5.0.3",
1010
"scripts": {
11-
"prebuild": "rm -rf dist",
12-
"build": "tsc",
13-
"start": "tsc --watch"
11+
"prebuild": "del /s /q dist",
12+
"build": "yarn prebuild && tsc",
13+
"start": "tsc --watch",
14+
"prepare": "install-peers",
15+
"test-windows": "npm run prepare && npm run build && npm run jest",
16+
"test": "yarn prepare && yarn build && yarn jest"
1417
},
1518
"main": "dist/index.js",
1619
"exports": "./dist/index.js",
1720
"types": "dist/index.d.ts",
1821
"files": [
1922
"/dist"
2023
],
24+
"jest": {
25+
"setupFilesAfterEnv": [
26+
"./jest.setup.js"
27+
],
28+
"collectCoverage": true
29+
},
2130
"dependencies": {
2231
"@soroban-react/core": "^5.0.3",
2332
"soroban-client": "0.8.0"
2433
},
2534
"devDependencies": {
26-
"@types/react": "^18.0.25"
35+
"@babel/preset-react": "^7.22.5",
36+
"@testing-library/react-hooks": "^8.0.1",
37+
"@types/jest": "^29.5.2",
38+
"@types/react": "^18.0.25",
39+
"install-peers-cli": "^2.2.0",
40+
"jest": "^29.5.0",
41+
"jsdom": "^22.1.0",
42+
"ts-jest": "^29.1.0"
2743
},
2844
"peerDependencies": {
2945
"react": ">=16.8"
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const yourFileExports = require('../dist/index.js')
2+
3+
describe('Module exports', () => {
4+
test('should export useContractValue', () => {
5+
expect(yourFileExports.useContractValue).toBeDefined()
6+
})
7+
8+
test('should export useSendTransaction', () => {
9+
expect(yourFileExports.useSendTransaction).toBeDefined()
10+
})
11+
12+
test('should export setTrustline', () => {
13+
expect(yourFileExports.setTrustline).toBeDefined()
14+
})
15+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
const { setTrustline } = require('../dist/setTrustline')
2+
3+
describe('setTrustline', () => {
4+
const tokenSymbol = 'TST'
5+
const tokenAdmin = 'GJYN5MDN3RV7WQXBGJHNAGB4XSZMH6ODOV62SMKJOHOQCSPFMCYD2PTI'
6+
const account = 'GBRIRLB2XNFKPNRUHBJDTSJI5KVLZRLZAOU7TCGKITA3SZU3IBJKKXBV'
7+
const sorobanContext = {
8+
server: 'https://soroban-rpc.stellar.org',
9+
activeChain: {
10+
networkPassphrase: 'Test SoroNet',
11+
},
12+
}
13+
const sendTransaction = jest.fn()
14+
15+
beforeEach(() => {
16+
jest.clearAllMocks()
17+
})
18+
19+
test('should throw error if not connected to server', async () => {
20+
sorobanContext.server = ''
21+
await expect(
22+
setTrustline({
23+
tokenSymbol,
24+
tokenAdmin,
25+
account,
26+
sorobanContext,
27+
sendTransaction,
28+
})
29+
).rejects.toThrowError('Not connected to server')
30+
})
31+
32+
test('should throw error if no networkPassphrase', async () => {
33+
sorobanContext.server = 'https://soroban-rpc.stellar.org'
34+
sorobanContext.activeChain.networkPassphrase = ''
35+
await expect(
36+
setTrustline({
37+
tokenSymbol,
38+
tokenAdmin,
39+
account,
40+
sorobanContext,
41+
sendTransaction,
42+
})
43+
).rejects.toThrowError('No networkPassphrase')
44+
})
45+
46+
test('should call sendTransaction with trustline transaction', async () => {
47+
const mockAccount = {
48+
sequence: '1234567890', // Must be a string to mimic Soroban Server response
49+
}
50+
const transactionBuilderSpy = jest
51+
.spyOn(SorobanClient, 'TransactionBuilder')
52+
.mockImplementation(() => ({
53+
setTimeout: jest.fn().mockReturnThis(),
54+
addOperation: jest.fn().mockReturnThis(),
55+
build: jest.fn().mockReturnValue({
56+
toEnvelope: jest.fn().mockReturnValue('transaction envelope'),
57+
hash: jest.fn().mockReturnValue('transaction hash'),
58+
}),
59+
}))
60+
const serverGetAccountSpy = jest
61+
.spyOn(sorobanContext.server, 'getAccount')
62+
.mockResolvedValue(mockAccount)
63+
64+
await setTrustline({
65+
tokenSymbol,
66+
tokenAdmin,
67+
account,
68+
sorobanContext,
69+
sendTransaction,
70+
})
71+
72+
expect(serverGetAccountSpy).toHaveBeenCalledWith(account)
73+
expect(transactionBuilderSpy).toHaveBeenCalledWith(mockAccount, {
74+
networkPassphrase: sorobanContext.activeChain.networkPassphrase,
75+
fee: '1000',
76+
})
77+
expect(sendTransaction).toHaveBeenCalledWith(
78+
{ toEnvelope: expect.any(Function), hash: expect.any(Function) },
79+
{ timeout: 60000, skipAddingFootprint: true, sorobanContext }
80+
)
81+
})
82+
})

packages/core/coverage/clover.xml

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<coverage generated="1687474184322" clover="3.2.0">
3-
<project timestamp="1687474184323" name="All files">
2+
<coverage generated="1687978653479" clover="3.2.0">
3+
<project timestamp="1687978653479" name="All files">
44
<metrics statements="148" coveredstatements="125" conditionals="201" coveredconditionals="153" methods="50" coveredmethods="37" elements="399" coveredelements="315" complexity="0" loc="148" ncloc="148" packages="1" files="5" classes="5"/>
5-
<file name="SorobanContext.js" path="E:\work\test\soroban-react-testing\soroban-react-testing\packages\core\dist\SorobanContext.js">
5+
<file name="SorobanContext.js" path="C:\Users\herts\OneDrive\Escritorio\proyectos\soroban-react\packages\core\dist\SorobanContext.js">
66
<metrics statements="32" coveredstatements="26" conditionals="46" coveredconditionals="33" methods="17" coveredmethods="11"/>
77
<line num="2" count="4" type="cond" truecount="4" falsecount="1"/>
88
<line num="3" count="1" type="cond" truecount="1" falsecount="1"/>
@@ -37,7 +37,7 @@
3737
<line num="47" count="1" type="stmt"/>
3838
<line num="50" count="4" type="stmt"/>
3939
</file>
40-
<file name="SorobanReactProvider.js" path="E:\work\test\soroban-react-testing\soroban-react-testing\packages\core\dist\SorobanReactProvider.js">
40+
<file name="SorobanReactProvider.js" path="C:\Users\herts\OneDrive\Escritorio\proyectos\soroban-react\packages\core\dist\SorobanReactProvider.js">
4141
<metrics statements="85" coveredstatements="70" conditionals="129" coveredconditionals="102" methods="27" coveredmethods="21"/>
4242
<line num="2" count="2" type="cond" truecount="4" falsecount="1"/>
4343
<line num="3" count="57" type="cond" truecount="1" falsecount="1"/>
@@ -125,7 +125,7 @@
125125
<line num="146" count="7" type="stmt"/>
126126
<line num="148" count="2" type="stmt"/>
127127
</file>
128-
<file name="getDefaultConnectors.js" path="E:\work\test\soroban-react-testing\soroban-react-testing\packages\core\dist\getDefaultConnectors.js">
128+
<file name="getDefaultConnectors.js" path="C:\Users\herts\OneDrive\Escritorio\proyectos\soroban-react\packages\core\dist\getDefaultConnectors.js">
129129
<metrics statements="7" coveredstatements="7" conditionals="0" coveredconditionals="0" methods="1" coveredmethods="1"/>
130130
<line num="2" count="3" type="stmt"/>
131131
<line num="3" count="3" type="stmt"/>
@@ -135,7 +135,7 @@
135135
<line num="7" count="3" type="stmt"/>
136136
<line num="9" count="3" type="stmt"/>
137137
</file>
138-
<file name="index.js" path="E:\work\test\soroban-react-testing\soroban-react-testing\packages\core\dist\index.js">
138+
<file name="index.js" path="C:\Users\herts\OneDrive\Escritorio\proyectos\soroban-react\packages\core\dist\index.js">
139139
<metrics statements="15" coveredstatements="13" conditionals="24" coveredconditionals="16" methods="4" coveredmethods="3"/>
140140
<line num="2" count="2" type="cond" truecount="4" falsecount="1"/>
141141
<line num="3" count="10" type="cond" truecount="1" falsecount="1"/>
@@ -153,7 +153,7 @@
153153
<line num="19" count="2" type="stmt"/>
154154
<line num="20" count="2" type="stmt"/>
155155
</file>
156-
<file name="useSorobanReact.js" path="E:\work\test\soroban-react-testing\soroban-react-testing\packages\core\dist\useSorobanReact.js">
156+
<file name="useSorobanReact.js" path="C:\Users\herts\OneDrive\Escritorio\proyectos\soroban-react\packages\core\dist\useSorobanReact.js">
157157
<metrics statements="9" coveredstatements="9" conditionals="2" coveredconditionals="2" methods="1" coveredmethods="1"/>
158158
<line num="2" count="3" type="stmt"/>
159159
<line num="3" count="3" type="stmt"/>

0 commit comments

Comments
 (0)