Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v0.8.0 #136

Merged
merged 37 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b6ff821
chore: add jest setup to coverage all files (#101)
Brunonascdev Mar 26, 2024
e78148d
refactor: fix circular import
fazzatti Mar 26, 2024
e9497cb
test: contract engine initial structure
fazzatti Mar 26, 2024
1d20ca7
Merge pull request #102 from CheesecakeLabs/unit-test
Brunonascdev Mar 26, 2024
a4a6bde
Contract Engine unit tests (#103)
fazzatti Mar 28, 2024
f66a40c
refactor: contract engine errors (#104)
fazzatti Mar 28, 2024
47ccf16
Update docs and minor adjustments to jsdocs (#105)
fazzatti Mar 28, 2024
c30ab86
packaging: bump version to 0.7.0 (#108)
fazzatti Mar 28, 2024
81b25eb
test: add build transaction unit tests
Brunonascdev Apr 1, 2024
1a17047
Merge branch 'develop' of github.com:CheesecakeLabs/stellar-plus into…
Brunonascdev Apr 1, 2024
961ad28
chore: merge with develop
Brunonascdev Apr 1, 2024
7249e02
test: add build transaction failure tests
Brunonascdev Apr 1, 2024
44561cb
refactor: make networkConfig variable private
Brunonascdev Apr 1, 2024
ec59df0
Merge pull request #110 from CheesecakeLabs/test/build-transaction-un…
Brunonascdev Apr 1, 2024
d8924db
test: add unit test for fee bump pipeline (#113)
Brunonascdev Apr 1, 2024
88a8b0a
test: add unit tests for classic signature requirements pipeline (#115)
fazzatti Apr 1, 2024
619b65f
Add unit tests for simulate transaction pipeline (#117)
fazzatti Apr 2, 2024
9712847
Add unit tests for classic transaction pipeline (#118)
fazzatti Apr 2, 2024
e2d382a
test: add unit tests for soroban transaction pipeline (#119)
fazzatti Apr 2, 2024
0da0a45
test: add unit test for sign transaction pipeline
Brunonascdev Apr 2, 2024
85c2044
Merge branch 'develop' of github.com:CheesecakeLabs/stellar-plus into…
Brunonascdev Apr 2, 2024
13e354a
Merge pull request #120 from CheesecakeLabs/test/sign-transaction-pip…
Brunonascdev Apr 2, 2024
72d7b93
test: add unit test for submit transaction pipeline
Brunonascdev Apr 3, 2024
ef9c214
Merge pull request #122 from CheesecakeLabs/test/submit-transaction-p…
Brunonascdev Apr 3, 2024
0d57031
Add unit tests soroban auth (#123)
fazzatti Apr 3, 2024
882cd85
Complete unit test coverage for account handlers (#125)
fazzatti Apr 5, 2024
10ace5d
Create test-coverage.yml action (#126)
fazzatti Apr 5, 2024
89405b9
Add unit test for base account handler (#127)
fazzatti Apr 5, 2024
4ab013b
Add unit test for soroban get transaction pipeline (#124)
fazzatti Apr 5, 2024
228a50f
Add unit tests for the classic asset handler (#128)
fazzatti Apr 5, 2024
4823037
feat: remove issuer requirement for classic assets (#129)
fazzatti Apr 8, 2024
210cbd7
test: add unit test to soroban token handler (#131)
fazzatti Apr 24, 2024
cf4b2e9
feat: remove helper classes for account (#132)
fazzatti Apr 24, 2024
c008ca6
Standardize default network configs and custom (#133)
fazzatti Apr 25, 2024
20abb09
packaging: bump version to v0.8.0
fazzatti Apr 25, 2024
158165a
Merge branch 'main' into develop
fazzatti Apr 25, 2024
5bf176a
Fix merge issues (#137)
fazzatti Apr 25, 2024
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
4 changes: 2 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": ["tsconfig.json"]
"project": ["tsconfig.json"],
"exclude": "commitlint.config.js"
},
"exclude": "commitlint.config.js",
"plugins": ["@typescript-eslint", "prettier", "unicorn", "import"],
"extends": [
"eslint:recommended",
Expand Down
51 changes: 51 additions & 0 deletions .github/workflows/test-coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: Node.js CI

on:
workflow_dispatch:
workflow_call:
push:
branches: [ "develop", "main" ]
pull_request:
branches: [ "develop", "main" ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 16
cache: 'npm'
cache-dependency-path: './package-lock.json'

- name: Install Dependencies
run: npm ci

- name: Run tests with coverage
run: npm test

- name: Code Coverage Report
uses: irongut/CodeCoverageSummary@v1.3.0
with:
filename: ./src/coverage/cobertura-coverage.xml
fail_below_min: false
format: markdown
hide_branch_rate: false
hide_complexity: true
indicators: true
output: both
thresholds: '60 80'

- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@v2
if: github.event_name == 'pull_request'
with:
recreate: true
path: code-coverage-results.md
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stellar-plus",
"version": "0.7.0",
"version": "0.8.0",
"description": "beta version of stellar-plus, an all-in-one sdk for the Stellar blockchain",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
Expand Down
11 changes: 9 additions & 2 deletions src/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ module.exports = {
testEnvironment: 'node',
collectCoverage: true,
coverageReporters: ['cobertura', 'json', 'html', 'text'],
coveragePathIgnorePatterns: ['/node_modules/', '<rootDir>/*/.*\\.types.ts', '.*\\mocks.ts', './coverage/'],
collectCoverageFrom: ['./**/*.ts'],
collectCoverageFrom: [
'./**/*.ts',
'!<rootDir>/*/.*\\.types.ts',
'!<rootDir>/*/.*\\.mocks.ts',
'!<rootDir>/dist/',
'!/node_modules/',
'!/coverage/',
],
coveragePathIgnorePatterns: ['<rootDir>/index-test.ts'],
setupFilesAfterEnv: ['./setup-tests.ts'],
modulePathIgnorePatterns: ['<rootDir>/dist/'],
moduleDirectories: ['node_modules', 'src'],
Expand Down
11 changes: 5 additions & 6 deletions src/stellar-plus/account/account-handler/default/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { FeeBumpTransaction, Keypair, Transaction, authorizeEntry, xdr } from '@stellar/stellar-sdk'

import { DAHError } from 'stellar-plus/account/account-handler/default/errors'
import { DefaultAccountHandler, DefaultAccountHandlerPayload } from 'stellar-plus/account/account-handler/default/types'
import { AccountBaseClient } from 'stellar-plus/account/base'
import { AccountBase } from 'stellar-plus/account/base'
import { TransactionXdr } from 'stellar-plus/types'

import { DAHError } from './errors'

export class DefaultAccountHandlerClient extends AccountBaseClient implements DefaultAccountHandler {
export class DefaultAccountHandlerClient extends AccountBase implements DefaultAccountHandler {
protected secretKey: string

/**
Expand All @@ -16,8 +15,8 @@ export class DefaultAccountHandlerClient extends AccountBaseClient implements De
* @param {NetworkConfig} payload.networkConfig The network to use.
* @description - The default account handler is used for handling and creating new accounts by directly manipulating the secret key.
*/
constructor(payload: DefaultAccountHandlerPayload) {
const secretKey = payload.secretKey as string
constructor(payload?: DefaultAccountHandlerPayload) {
const secretKey = payload?.secretKey as string
try {
const keypair = secretKey ? Keypair.fromSecret(secretKey) : Keypair.random()

Expand Down
162 changes: 162 additions & 0 deletions src/stellar-plus/account/account-handler/default/index.unit.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import { FeeBumpTransaction, Keypair, Transaction, authorizeEntry, xdr } from '@stellar/stellar-sdk'

import { DefaultAccountHandlerClient } from 'stellar-plus/account/account-handler/default'
import { DAHError } from 'stellar-plus/account/account-handler/default/errors'
import { TestNet } from 'stellar-plus/network'

jest.mock('@stellar/stellar-sdk', () => {
// The mock doesnt spread the whole originalModule because some internal exported objects cause failures
// so we just unmock the necessary items.
// uncomment and use the following line if you need to check the contents of the module:
// const originalModule: typeof import('@stellar/stellar-sdk') = jest.requireActual('@stellar/stellar-sdk')
const originalModule = jest.requireActual('@stellar/stellar-sdk')
return {
Horizon: originalModule.Horizon,
Keypair: originalModule.Keypair,
Transaction: originalModule.Transaction,
FeeBumpTransaction: originalModule.FeeBumpTransaction,
xdr: originalModule.xdr,
authorizeEntry: jest.fn(),
}
})

const MOCKED_AUTHORIZE_ENTRY = authorizeEntry as jest.Mock

const MOCKED_SOROBAN_AUTH_ENTRY = {
credentials: jest.fn(),
rootInvocation: jest.fn(),
toXDR: jest.fn(),
} as xdr.SorobanAuthorizationEntry

const TESTNET_CONFIG = TestNet()

describe('DefaultAccountHandler', () => {
describe('Initialization', () => {
it('should initialize with just the networkConfig and generate a keypair', () => {
const dah = new DefaultAccountHandlerClient({ networkConfig: TESTNET_CONFIG })
const spySecretKey = jest.mocked((dah as any).secretKey)

expect(spySecretKey).toBeDefined()
expect(dah.getPublicKey()).toBe(Keypair.fromSecret(spySecretKey as string).publicKey())
})

it('should initialize with a secret key', () => {
const secretKey = Keypair.random().secret()
const dah = new DefaultAccountHandlerClient({ networkConfig: TESTNET_CONFIG, secretKey })

expect(dah.getPublicKey()).toBe(Keypair.fromSecret(secretKey).publicKey())
})

it('should sign a transaction with its secret key', () => {
const keypair = Keypair.random()
const dah = new DefaultAccountHandlerClient({ networkConfig: TESTNET_CONFIG, secretKey: keypair.secret() })
const mockedXdrResult = 'Mocked XDR Result'
const mockedTx = {
sign: jest.fn().mockReturnValue('Signed'),
toXDR: jest.fn().mockReturnValue(mockedXdrResult),
} as unknown as Transaction
const spySign = jest.spyOn(mockedTx, 'sign')

const signedTx = dah.sign(mockedTx)

expect(signedTx).toBe(mockedXdrResult)
expect(spySign).toHaveBeenCalledExactlyOnceWith(keypair)
})

it('should sign a fee bummp transaction with its secret key', () => {
const keypair = Keypair.random()
const dah = new DefaultAccountHandlerClient({ networkConfig: TESTNET_CONFIG, secretKey: keypair.secret() })
const mockedXdrResult = 'Mocked XDR Result'
const mockedTx = {
sign: jest.fn().mockReturnValue('Signed'),
toXDR: jest.fn().mockReturnValue(mockedXdrResult),
} as unknown as FeeBumpTransaction
const spySign = jest.spyOn(mockedTx, 'sign')

const signedTx = dah.sign(mockedTx)

expect(signedTx).toBe(mockedXdrResult)
expect(spySign).toHaveBeenCalledExactlyOnceWith(keypair)
})

it('should sign a soroban authorization entry with its secret key', async () => {
const keypair = Keypair.random()
MOCKED_AUTHORIZE_ENTRY.mockImplementationOnce(() => MOCKED_SOROBAN_AUTH_ENTRY)
const dah = new DefaultAccountHandlerClient({ networkConfig: TESTNET_CONFIG, secretKey: keypair.secret() })

const signedEntry = await dah.signSorobanAuthEntry(
MOCKED_SOROBAN_AUTH_ENTRY,
123,
TESTNET_CONFIG.networkPassphrase
)

expect(signedEntry).toBe(MOCKED_SOROBAN_AUTH_ENTRY)
expect(MOCKED_AUTHORIZE_ENTRY).toHaveBeenCalledExactlyOnceWith(
MOCKED_SOROBAN_AUTH_ENTRY,
keypair,
123,
TESTNET_CONFIG.networkPassphrase
)
})
})

describe('Error Handling', () => {
beforeEach(() => {
jest.clearAllMocks()
})

it('should throw an error if the secret key provided in the constructor is invalid', () => {
const invalidSecretKey = 'Mocked Secret Key'

expect(() => {
new DefaultAccountHandlerClient({ networkConfig: TESTNET_CONFIG, secretKey: invalidSecretKey })
}).toThrow(DAHError.failedToLoadSecretKeyError(new Error('Mocked error')))
})

it('should throw an error if the public key cannot be derived from the current secret key', () => {
const invalidSecret = 'Mocked Secret Key'
const dah = new DefaultAccountHandlerClient({ networkConfig: TESTNET_CONFIG })
jest.replaceProperty(dah as any, 'secretKey', invalidSecret)

expect(dah.getPublicKey).toThrow(DAHError.failedToLoadSecretKeyError(new Error('Mocked error')))
})

it('should throw an error if the transaction cannot be signed', () => {
const keypair = Keypair.random()
const dah = new DefaultAccountHandlerClient({ networkConfig: TESTNET_CONFIG, secretKey: keypair.secret() })
const mockedTx = {
sign: jest.fn().mockImplementationOnce(() => {
throw new Error('Mocked error')
}),
toXDR: jest.fn(),
} as unknown as Transaction
const spySign = jest.spyOn(mockedTx, 'sign')

expect(() => {
dah.sign(mockedTx)
}).toThrow(DAHError.failedToSignTransactionError(new Error('Mocked error')))
expect(spySign).toHaveBeenCalledExactlyOnceWith(keypair)
})

it('should throw an error if the authorizeEntry cannot be signed', async () => {
const keypair = Keypair.random()
MOCKED_AUTHORIZE_ENTRY.mockImplementationOnce(() => {
throw new Error('Mocked error')
})
const dah = new DefaultAccountHandlerClient({ networkConfig: TESTNET_CONFIG, secretKey: keypair.secret() })

await expect(
dah.signSorobanAuthEntry(MOCKED_SOROBAN_AUTH_ENTRY, 123, TESTNET_CONFIG.networkPassphrase)
).rejects.toThrow(
DAHError.failedToSignAuthorizationEntryError(
new Error('Mocked error'),
'mocked auth entry xdr',
123,
TESTNET_CONFIG.networkPassphrase
)
)
})
})
})

This file was deleted.

Loading
Loading