Skip to content

Commit

Permalink
feat: remove spec requirement for contract engine (#145)
Browse files Browse the repository at this point in the history
* chore: add jest setup to coverage all files (#101)

* refactor: fix circular import

* test: contract engine initial structure

* Contract Engine unit tests (#103)

* refactor: contract engine errors

* feat: validate required initialization arguments

* test: contract engine initialization workflow

* test: complete contract engine main coverage

* refactor: update deprecated methods

* refactor: contract engine errors (#104)

* Update docs and minor adjustments to jsdocs (#105)

* fix: missing error CE009

* docs: update jsdoc

* docs: update readme for public release

* packaging: bump version to 0.7.0 (#108)

* test: add build transaction unit tests

* chore: merge with develop

* test: add build transaction failure tests

* refactor: make networkConfig variable private

* test: add unit test for fee bump pipeline (#113)

* test: add unit tests for classic signature requirements pipeline (#115)

* Adjustments to release library as open source 🚀  (#107)

* chore: add jest setup to coverage all files (#101)

* refactor: fix circular import

* test: contract engine initial structure

* Contract Engine unit tests (#103)

* refactor: contract engine errors

* feat: validate required initialization arguments

* test: contract engine initialization workflow

* test: complete contract engine main coverage

* refactor: update deprecated methods

* refactor: contract engine errors (#104)

* Update docs and minor adjustments to jsdocs (#105)

* fix: missing error CE009

* docs: update jsdoc

* docs: update readme for public release

* packaging: bump version to 0.7.0 (#108)

---------

Co-authored-by: Bruno Nascimento <[email protected]>

* fix: setoptions op threshold requirement

* fix: revoke operation variants threshold calculation

* test: add unit tests to classig sign requirements pipeline

* refactor: rearrange as per aaa pattern

---------

Co-authored-by: Bruno Nascimento <[email protected]>

* Add unit tests for simulate transaction pipeline (#117)

* refactor: eslint adjustments

* test: initial simulate transaction unit tests

* feat: add assemble transaction sp error

* test: complete coverage for simulate transaction pipeline

* refactor: clean up comments and adjust imports

* Add unit tests for classic transaction pipeline (#118)

* test: add unit tests for classic transaction pipeline

* refactor: adjust imports

* test: add unit tests for soroban transaction pipeline (#119)

* test: add unit test for sign transaction pipeline

* test: add unit test for submit transaction pipeline

* Add unit tests soroban auth (#123)

* fix: remove validation from contract engine initialization

* style: remove comment

* feat: modify account handler mocker payload

* test: add unit test to soroban auth pipeline

---------

Co-authored-by: Bruno Nascimento <[email protected]>

* Complete unit test coverage for account handlers (#125)

* test: add unit tests for the default account handler

* test: validate error to sign auth entry

* feat: add fee bump type to sign payload

* test: refactor freighter account handler unit tests

* Create test-coverage.yml action (#126)

* Create test-coverage.yml action

* Update test-coverage.yml

* Add unit test for base account handler (#127)

* test: add unit tests for the default account handler

* test: validate error to sign auth entry

* feat: add fee bump type to sign payload

* test: refactor freighter account handler unit tests

* test: add unit tests for base account handler

* Add unit test for soroban get transaction pipeline (#124)

* refactor: soroban get transaction pipeline constructor

* fix: remove old log

* test: add unit tests for soroban get transaction pipeline

* style: adjust imports

* Add unit tests for the classic asset handler (#128)

* refactor: adjust outter imports/exports

* test: add unit tests for the classic asset handler

* feat: remove issuer requirement for classic assets (#129)

* refactor: allow for no payload for dah

* feat: remove issuer necessity for classic assets to better include native

* test: add unit test to soroban token handler (#131)

* feat: remove helper classes for account (#132)

* feat: remove helper classes for account

* refactor: remove unused error for base account

* test: complete unit coverage for base account errors

* Standardize default network configs and custom (#133)

* feat: standardize network config options as functions under network

* test: adjust tests for new network config format

* feat: require rpc url for default rpc handler to initialize

* feat: require horizon url to initialize default horizon handler

* test: remove local testing from coverage

* feat: remove soroban client

* feat: convert horizon load account error to sp error

* feat: add allowhttp to network config

* test: add unit tests to default horizon handler

* test: add default rpc handler unit tests

* fix: account changes with network new config format

* test: add network configuration unit tests

* refactor: allowhttp object

Co-authored-by: Caio Teixeira <[email protected]>

---------

Co-authored-by: Caio Teixeira <[email protected]>

* packaging: bump version to v0.8.0

* Fix merge issues (#137)

* feat: standardize network config options as functions under network

* fix: duplicate imports

* Update stellar sdk (#139)

* Release v0.8.0 (#136)

* chore: add jest setup to coverage all files (#101)

* refactor: fix circular import

* test: contract engine initial structure

* Contract Engine unit tests (#103)

* refactor: contract engine errors

* feat: validate required initialization arguments

* test: contract engine initialization workflow

* test: complete contract engine main coverage

* refactor: update deprecated methods

* refactor: contract engine errors (#104)

* Update docs and minor adjustments to jsdocs (#105)

* fix: missing error CE009

* docs: update jsdoc

* docs: update readme for public release

* packaging: bump version to 0.7.0 (#108)

* test: add build transaction unit tests

* chore: merge with develop

* test: add build transaction failure tests

* refactor: make networkConfig variable private

* test: add unit test for fee bump pipeline (#113)

* test: add unit tests for classic signature requirements pipeline (#115)

* Adjustments to release library as open source 🚀  (#107)

* chore: add jest setup to coverage all files (#101)

* refactor: fix circular import

* test: contract engine initial structure

* Contract Engine unit tests (#103)

* refactor: contract engine errors

* feat: validate required initialization arguments

* test: contract engine initialization workflow

* test: complete contract engine main coverage

* refactor: update deprecated methods

* refactor: contract engine errors (#104)

* Update docs and minor adjustments to jsdocs (#105)

* fix: missing error CE009

* docs: update jsdoc

* docs: update readme for public release

* packaging: bump version to 0.7.0 (#108)

---------

Co-authored-by: Bruno Nascimento <[email protected]>

* fix: setoptions op threshold requirement

* fix: revoke operation variants threshold calculation

* test: add unit tests to classig sign requirements pipeline

* refactor: rearrange as per aaa pattern

---------

Co-authored-by: Bruno Nascimento <[email protected]>

* Add unit tests for simulate transaction pipeline (#117)

* refactor: eslint adjustments

* test: initial simulate transaction unit tests

* feat: add assemble transaction sp error

* test: complete coverage for simulate transaction pipeline

* refactor: clean up comments and adjust imports

* Add unit tests for classic transaction pipeline (#118)

* test: add unit tests for classic transaction pipeline

* refactor: adjust imports

* test: add unit tests for soroban transaction pipeline (#119)

* test: add unit test for sign transaction pipeline

* test: add unit test for submit transaction pipeline

* Add unit tests soroban auth (#123)

* fix: remove validation from contract engine initialization

* style: remove comment

* feat: modify account handler mocker payload

* test: add unit test to soroban auth pipeline

---------

Co-authored-by: Bruno Nascimento <[email protected]>

* Complete unit test coverage for account handlers (#125)

* test: add unit tests for the default account handler

* test: validate error to sign auth entry

* feat: add fee bump type to sign payload

* test: refactor freighter account handler unit tests

* Create test-coverage.yml action (#126)

* Create test-coverage.yml action

* Update test-coverage.yml

* Add unit test for base account handler (#127)

* test: add unit tests for the default account handler

* test: validate error to sign auth entry

* feat: add fee bump type to sign payload

* test: refactor freighter account handler unit tests

* test: add unit tests for base account handler

* Add unit test for soroban get transaction pipeline (#124)

* refactor: soroban get transaction pipeline constructor

* fix: remove old log

* test: add unit tests for soroban get transaction pipeline

* style: adjust imports

* Add unit tests for the classic asset handler (#128)

* refactor: adjust outter imports/exports

* test: add unit tests for the classic asset handler

* feat: remove issuer requirement for classic assets (#129)

* refactor: allow for no payload for dah

* feat: remove issuer necessity for classic assets to better include native

* test: add unit test to soroban token handler (#131)

* feat: remove helper classes for account (#132)

* feat: remove helper classes for account

* refactor: remove unused error for base account

* test: complete unit coverage for base account errors

* Standardize default network configs and custom (#133)

* feat: standardize network config options as functions under network

* test: adjust tests for new network config format

* feat: require rpc url for default rpc handler to initialize

* feat: require horizon url to initialize default horizon handler

* test: remove local testing from coverage

* feat: remove soroban client

* feat: convert horizon load account error to sp error

* feat: add allowhttp to network config

* test: add unit tests to default horizon handler

* test: add default rpc handler unit tests

* fix: account changes with network new config format

* test: add network configuration unit tests

* refactor: allowhttp object

Co-authored-by: Caio Teixeira <[email protected]>

---------

Co-authored-by: Caio Teixeira <[email protected]>

* packaging: bump version to v0.8.0

* Fix merge issues (#137)

* feat: standardize network config options as functions under network

* fix: duplicate imports

---------

Co-authored-by: Bruno Nascimento <[email protected]>
Co-authored-by: Caio Teixeira <[email protected]>

* chore: update stellar sdk

* feat: add function to return secret key to default account handler

* test: default account handler getters

---------

Co-authored-by: Bruno Nascimento <[email protected]>
Co-authored-by: Caio Teixeira <[email protected]>

* packaging: bump version to 0.8.1

* Minor fixes (#141)

* feat: standardize network config options as functions under network

* fix: duplicate imports

* fix: read from contract output

* chore: bump version

* chore: bump version to 0.8.2

* Contract engine improvements (#144)

* feat: standardize network config options as functions under network

* fix: duplicate imports

* version 0.8.2 (#142)

* chore: add jest setup to coverage all files (#101)

* refactor: fix circular import

* test: contract engine initial structure

* Contract Engine unit tests (#103)

* refactor: contract engine errors

* feat: validate required initialization arguments

* test: contract engine initialization workflow

* test: complete contract engine main coverage

* refactor: update deprecated methods

* refactor: contract engine errors (#104)

* Update docs and minor adjustments to jsdocs (#105)

* fix: missing error CE009

* docs: update jsdoc

* docs: update readme for public release

* packaging: bump version to 0.7.0 (#108)

* test: add build transaction unit tests

* chore: merge with develop

* test: add build transaction failure tests

* refactor: make networkConfig variable private

* test: add unit test for fee bump pipeline (#113)

* test: add unit tests for classic signature requirements pipeline (#115)

* Adjustments to release library as open source 🚀  (#107)

* chore: add jest setup to coverage all files (#101)

* refactor: fix circular import

* test: contract engine initial structure

* Contract Engine unit tests (#103)

* refactor: contract engine errors

* feat: validate required initialization arguments

* test: contract engine initialization workflow

* test: complete contract engine main coverage

* refactor: update deprecated methods

* refactor: contract engine errors (#104)

* Update docs and minor adjustments to jsdocs (#105)

* fix: missing error CE009

* docs: update jsdoc

* docs: update readme for public release

* packaging: bump version to 0.7.0 (#108)

---------

Co-authored-by: Bruno Nascimento <[email protected]>

* fix: setoptions op threshold requirement

* fix: revoke operation variants threshold calculation

* test: add unit tests to classig sign requirements pipeline

* refactor: rearrange as per aaa pattern

---------

Co-authored-by: Bruno Nascimento <[email protected]>

* Add unit tests for simulate transaction pipeline (#117)

* refactor: eslint adjustments

* test: initial simulate transaction unit tests

* feat: add assemble transaction sp error

* test: complete coverage for simulate transaction pipeline

* refactor: clean up comments and adjust imports

* Add unit tests for classic transaction pipeline (#118)

* test: add unit tests for classic transaction pipeline

* refactor: adjust imports

* test: add unit tests for soroban transaction pipeline (#119)

* test: add unit test for sign transaction pipeline

* test: add unit test for submit transaction pipeline

* Add unit tests soroban auth (#123)

* fix: remove validation from contract engine initialization

* style: remove comment

* feat: modify account handler mocker payload

* test: add unit test to soroban auth pipeline

---------

Co-authored-by: Bruno Nascimento <[email protected]>

* Complete unit test coverage for account handlers (#125)

* test: add unit tests for the default account handler

* test: validate error to sign auth entry

* feat: add fee bump type to sign payload

* test: refactor freighter account handler unit tests

* Create test-coverage.yml action (#126)

* Create test-coverage.yml action

* Update test-coverage.yml

* Add unit test for base account handler (#127)

* test: add unit tests for the default account handler

* test: validate error to sign auth entry

* feat: add fee bump type to sign payload

* test: refactor freighter account handler unit tests

* test: add unit tests for base account handler

* Add unit test for soroban get transaction pipeline (#124)

* refactor: soroban get transaction pipeline constructor

* fix: remove old log

* test: add unit tests for soroban get transaction pipeline

* style: adjust imports

* Add unit tests for the classic asset handler (#128)

* refactor: adjust outter imports/exports

* test: add unit tests for the classic asset handler

* feat: remove issuer requirement for classic assets (#129)

* refactor: allow for no payload for dah

* feat: remove issuer necessity for classic assets to better include native

* test: add unit test to soroban token handler (#131)

* feat: remove helper classes for account (#132)

* feat: remove helper classes for account

* refactor: remove unused error for base account

* test: complete unit coverage for base account errors

* Standardize default network configs and custom (#133)

* feat: standardize network config options as functions under network

* test: adjust tests for new network config format

* feat: require rpc url for default rpc handler to initialize

* feat: require horizon url to initialize default horizon handler

* test: remove local testing from coverage

* feat: remove soroban client

* feat: convert horizon load account error to sp error

* feat: add allowhttp to network config

* test: add unit tests to default horizon handler

* test: add default rpc handler unit tests

* fix: account changes with network new config format

* test: add network configuration unit tests

* refactor: allowhttp object

Co-authored-by: Caio Teixeira <[email protected]>

---------

Co-authored-by: Caio Teixeira <[email protected]>

* packaging: bump version to v0.8.0

* Fix merge issues (#137)

* feat: standardize network config options as functions under network

* fix: duplicate imports

* Update stellar sdk (#139)

* Release v0.8.0 (#136)

* chore: add jest setup to coverage all files (#101)

* refactor: fix circular import

* test: contract engine initial structure

* Contract Engine unit tests (#103)

* refactor: contract engine errors

* feat: validate required initialization arguments

* test: contract engine initialization workflow

* test: complete contract engine main coverage

* refactor: update deprecated methods

* refactor: contract engine errors (#104)

* Update docs and minor adjustments to jsdocs (#105)

* fix: missing error CE009

* docs: update jsdoc

* docs: update readme for public release

* packaging: bump version to 0.7.0 (#108)

* test: add build transaction unit tests

* chore: merge with develop

* test: add build transaction failure tests

* refactor: make networkConfig variable private

* test: add unit test for fee bump pipeline (#113)

* test: add unit tests for classic signature requirements pipeline (#115)

* Adjustments to release library as open source 🚀  (#107)

* chore: add jest setup to coverage all files (#101)

* refactor: fix circular import

* test: contract engine initial structure

* Contract Engine unit tests (#103)

* refactor: contract engine errors

* feat: validate required initialization arguments

* test: contract engine initialization workflow

* test: complete contract engine main coverage

* refactor: update deprecated methods

* refactor: contract engine errors (#104)

* Update docs and minor adjustments to jsdocs (#105)

* fix: missing error CE009

* docs: update jsdoc

* docs: update readme for public release

* packaging: bump version to 0.7.0 (#108)

---------

Co-authored-by: Bruno Nascimento <[email protected]>

* fix: setoptions op threshold requirement

* fix: revoke operation variants threshold calculation

* test: add unit tests to classig sign requirements pipeline

* refactor: rearrange as per aaa pattern

---------

Co-authored-by: Bruno Nascimento <[email protected]>

* Add unit tests for simulate transaction pipeline (#117)

* refactor: eslint adjustments

* test: initial simulate transaction unit tests

* feat: add assemble transaction sp error

* test: complete coverage for simulate transaction pipeline

* refactor: clean up comments and adjust imports

* Add unit tests for classic transaction pipeline (#118)

* test: add unit tests for classic transaction pipeline

* refactor: adjust imports

* test: add unit tests for soroban transaction pipeline (#119)

* test: add unit test for sign transaction pipeline

* test: add unit test for submit transaction pipeline

* Add unit tests soroban auth (#123)

* fix: remove validation from contract engine initialization

* style: remove comment

* feat: modify account handler mocker payload

* test: add unit test to soroban auth pipeline

---------

Co-authored-by: Bruno Nascimento <[email protected]>

* Complete unit test coverage for account handlers (#125)

* test: add unit tests for the default account handler

* test: validate error to sign auth entry

* feat: add fee bump type to sign payload

* test: refactor freighter account handler unit tests

* Create test-coverage.yml action (#126)

* Create test-coverage.yml action

* Update test-coverage.yml

* Add unit test for base account handler (#127)

* test: add unit tests for the default account handler

* test: validate error to sign auth entry

* feat: add fee bump type to sign payload

* test: refactor freighter account handler unit tests

* test: add unit tests for base account handler

* Add unit test for soroban get transaction pipeline (#124)

* refactor: soroban get transaction pipeline constructor

* fix: remove old log

* test: add unit tests for soroban get transaction pipeline

* style: adjust imports

* Add unit tests for the classic asset handler (#128)

* refactor: adjust outter imports/exports

* test: add unit tests for the classic asset handler

* feat: remove issuer requirement for classic assets (#129)

* refactor: allow for no payload for dah

* feat: remove issuer necessity for classic assets to better include native

* test: add unit test to soroban token handler (#131)

* feat: remove helper classes for account (#132)

* feat: remove helper classes for account

* refactor: remove unused error for base account

* test: complete unit coverage for base account errors

* Standardize default network configs and custom (#133)

* feat: standardize network config options as functions under network

* test: adjust tests for new network config format

* feat: require rpc url for default rpc handler to initialize

* feat: require horizon url to initialize default horizon handler

* test: remove local testing from coverage

* feat: remove soroban client

* feat: convert horizon load account error to sp error

* feat: add allowhttp to network config

* test: add unit tests to default horizon handler

* test: add default rpc handler unit tests

* fix: account changes with network new config format

* test: add network configuration unit tests

* refactor: allowhttp object

Co-authored-by: Caio Teixeira <[email protected]>

---------

Co-authored-by: Caio Teixeira <[email protected]>

* packaging: bump version to v0.8.0

* Fix merge issues (#137)

* feat: standardize network config options as functions under network

* fix: duplicate imports

---------

Co-authored-by: Bruno Nascimento <[email protected]>
Co-authored-by: Caio Teixeira <[email protected]>

* chore: update stellar sdk

* feat: add function to return secret key to default account handler

* test: default account handler getters

---------

Co-authored-by: Bruno Nascimento <[email protected]>
Co-authored-by: Caio Teixeira <[email protected]>

* packaging: bump version to 0.8.1

* Minor fixes (#141)

* feat: standardize network config options as functions under network

* fix: duplicate imports

* fix: read from contract output

* chore: bump version

* chore: bump version to 0.8.2

---------

Co-authored-by: Bruno Nascimento <[email protected]>
Co-authored-by: Caio Teixeira <[email protected]>

* Documentation (#143)

* GITBOOK-34: No subject

* GITBOOK-35: update issuing your first asset tutorial

* GITBOOK-36: update CD tutorial

* GITBOOK-37: update profiler plugin

* GITBOOK-38: Remove soroban token duplicate link

* GITBOOK-39: update soroban token handler

* GITBOOK-40: Improve Validation Cloud RPC page

* GITBOOK-41: Improve the Welcome Page

* GITBOOK-42: Improve Quick Start page

* GITBOOK-45: Soroban Auth Pipeline

* GITBOOK-47: update general doc

---------

Co-authored-by: Fernanda Hahn <[email protected]>

* feat: remove spec requirement to instantiate contract engine

* test: add unit test to spec requirement

* feat: export stellar-sdk contract spec

---------

Co-authored-by: Bruno Nascimento <[email protected]>
Co-authored-by: Caio Teixeira <[email protected]>
Co-authored-by: Fernanda Hahn <[email protected]>

* chore: bump version to 0.8.3

---------

Co-authored-by: Bruno Nascimento <[email protected]>
Co-authored-by: Caio Teixeira <[email protected]>
Co-authored-by: Fernanda Hahn <[email protected]>
  • Loading branch information
4 people authored May 7, 2024
1 parent 663ff70 commit 38b68db
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 47 deletions.
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.8.2",
"version": "0.8.3",
"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
96 changes: 55 additions & 41 deletions src/stellar-plus/core/contract-engine/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,22 @@ export enum ContractEngineErrorCodes {
CE004 = 'CE004',
CE005 = 'CE005',
CE006 = 'CE006',
CE007 = 'CE007',
CE008 = 'CE008',
CE009 = 'CE009',

// CE1 Meta
CE101 = 'CE101',
CE102 = 'CE102',
CE103 = 'CE103',
}

const missingContractId = (): StellarPlusError => {
return new StellarPlusError({
code: ContractEngineErrorCodes.CE001,
message: 'Missing contract ID!',
source: 'ContractEngine',
details:
"Missing contract ID! This function requires a contract Id to be defined in this instance. You can either initialize the contract engine with a contract ID or use the 'deploy' function to deploy a new instance of the contract, which will automatically set the new contract Id for this instance.",
})
}

const missingWasm = (): StellarPlusError => {
return new StellarPlusError({
code: ContractEngineErrorCodes.CE002,
message: 'Missing wasm!',
source: 'ContractEngine',
details:
'Missing wasm! This function requires a buffer of the wasm file to be defined in this instance. You need to initialize the contract engine with a wasm file buffer.',
})
}

const missingWasmHash = (): StellarPlusError => {
return new StellarPlusError({
code: ContractEngineErrorCodes.CE003,
message: 'Missing wasm hash!',
source: 'ContractEngine',
details:
"Missing wasm hash! This function requires a wasm hash to be defined in this instance. You can either initialize the contract engine with a wasm hash or use the 'uploadWasm' function to upload a new wasm file, which will automatically set the new wasm hash for this instance.",
})
// CE2 Missing parameters
CE201 = 'CE201',
CE202 = 'CE202',
CE203 = 'CE203',
CE204 = 'CE204',
}

const contractIdAlreadySet = (): StellarPlusError => {
return new StellarPlusError({
code: ContractEngineErrorCodes.CE004,
code: ContractEngineErrorCodes.CE001,
message: 'Contract ID already set!',
source: 'ContractEngine',
details:
Expand All @@ -62,7 +35,7 @@ const contractIdAlreadySet = (): StellarPlusError => {

const contractInstanceNotFound = (ledgerEntries: SorobanRpc.Api.GetLedgerEntriesResponse): StellarPlusError => {
return new StellarPlusError({
code: ContractEngineErrorCodes.CE005,
code: ContractEngineErrorCodes.CE002,
message: 'Contract instance not found!',
source: 'ContractEngine',
details:
Expand All @@ -75,7 +48,7 @@ const contractInstanceMissingLiveUntilLedgerSeq = (
ledgerEntries?: SorobanRpc.Api.GetLedgerEntriesResponse
): StellarPlusError => {
return new StellarPlusError({
code: ContractEngineErrorCodes.CE006,
code: ContractEngineErrorCodes.CE003,
message: 'Contract instance missing live_until_ledger_seq!',
source: 'ContractEngine',
details:
Expand All @@ -86,7 +59,7 @@ const contractInstanceMissingLiveUntilLedgerSeq = (

const contractCodeNotFound = (ledgerEntries: SorobanRpc.Api.GetLedgerEntriesResponse): StellarPlusError => {
return new StellarPlusError({
code: ContractEngineErrorCodes.CE007,
code: ContractEngineErrorCodes.CE004,
message: 'Contract code not found!',
source: 'ContractEngine',
details:
Expand All @@ -99,7 +72,7 @@ const contractCodeMissingLiveUntilLedgerSeq = (
ledgerEntries?: SorobanRpc.Api.GetLedgerEntriesResponse
): StellarPlusError => {
return new StellarPlusError({
code: ContractEngineErrorCodes.CE008,
code: ContractEngineErrorCodes.CE005,
message: 'Contract code missing live_until_ledger_seq!',
source: 'ContractEngine',
details:
Expand All @@ -110,7 +83,7 @@ const contractCodeMissingLiveUntilLedgerSeq = (

const contractEngineClassFailedToInitialize = (): StellarPlusError => {
return new StellarPlusError({
code: ContractEngineErrorCodes.CE009,
code: ContractEngineErrorCodes.CE006,
message: 'Contract engine class failed to initialize!',
source: 'ContractEngine',
details:
Expand Down Expand Up @@ -150,10 +123,47 @@ const failedToWrapAsset = (error: StellarPlusError): StellarPlusError => {
})
}

const missingContractId = (): StellarPlusError => {
return new StellarPlusError({
code: ContractEngineErrorCodes.CE201,
message: 'Missing contract ID!',
source: 'ContractEngine',
details:
"Missing contract ID! This function requires a contract Id to be defined in this instance. You can either initialize the contract engine with a contract ID or use the 'deploy' function to deploy a new instance of the contract, which will automatically set the new contract Id for this instance.",
})
}

const missingWasm = (): StellarPlusError => {
return new StellarPlusError({
code: ContractEngineErrorCodes.CE202,
message: 'Missing wasm!',
source: 'ContractEngine',
details:
'Missing wasm! This function requires a buffer of the wasm file to be defined in this instance. You need to initialize the contract engine with a wasm file buffer.',
})
}

const missingWasmHash = (): StellarPlusError => {
return new StellarPlusError({
code: ContractEngineErrorCodes.CE203,
message: 'Missing wasm hash!',
source: 'ContractEngine',
details:
"Missing wasm hash! This function requires a wasm hash to be defined in this instance. You can either initialize the contract engine with a wasm hash or use the 'uploadWasm' function to upload a new wasm file, which will automatically set the new wasm hash for this instance.",
})
}

const missingSpec = (): StellarPlusError => {
return new StellarPlusError({
code: ContractEngineErrorCodes.CE204,
message: 'Missing spec!',
source: 'ContractEngine',
details:
'Missing spec! This function requires a spec to be defined in this instance. You need to initialize the contract engine with a spec.',
})
}

export const CEError = {
missingContractId,
missingWasm,
missingWasmHash,
contractIdAlreadySet,
contractInstanceNotFound,
contractInstanceMissingLiveUntilLedgerSeq,
Expand All @@ -163,4 +173,8 @@ export const CEError = {
failedToUploadWasm,
failedToDeployContract,
failedToWrapAsset,
missingContractId,
missingWasm,
missingWasmHash,
missingSpec,
}
15 changes: 11 additions & 4 deletions src/stellar-plus/core/contract-engine/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {
import { SorobanTransactionPipelineOutput } from '../pipelines/soroban-transaction/types'

export class ContractEngine {
private spec: ContractSpec
private spec?: ContractSpec
private contractId?: string
private wasm?: Buffer
private wasmHash?: string
Expand Down Expand Up @@ -245,19 +245,20 @@ export class ContractEngine {
simulateOnly: boolean = false
): Promise<SorobanTransactionPipelineOutput> {
this.requireContractId()
this.requireSpec()

const { method, methodArgs } = args
const txInvocation = { ...(args as SorobanInvokeArgs<object>) } as TransactionInvocation

const encodedArgs = this.spec.funcArgsToScVals(method, methodArgs)
const encodedArgs = this.spec!.funcArgsToScVals(method, methodArgs) // Spec verified in requireSpec

const contract = new Contract(this.contractId!) // Contract Id verified in requireContractId
const contractCallOperation = contract.call(method, ...encodedArgs)

const executionPlugins = [
...(simulateOnly
? [new ExtractInvocationOutputFromSimulationPlugin(this.spec, method)]
: [new ExtractInvocationOutputPlugin(this.spec, method)]),
? [new ExtractInvocationOutputFromSimulationPlugin(this.spec!, method)]
: [new ExtractInvocationOutputPlugin(this.spec!, method)]),
...(txInvocation.executionPlugins || []),
]

Expand Down Expand Up @@ -412,6 +413,12 @@ export class ContractEngine {
}
}

private requireSpec(): void {
if (!this.spec) {
throw CEError.missingSpec()
}
}

protected async getContractCodeLedgerEntry(): Promise<SorobanRpcNamespace.Api.LedgerEntryResult> {
this.requireWasmHash()

Expand Down
17 changes: 17 additions & 0 deletions src/stellar-plus/core/contract-engine/index.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,23 @@ describe('ContractEngine', () => {
CEError.missingContractId()
)
})

it('should throw if spec is required but not present', async () => {
const contractEngine = new ContractEngine({
networkConfig: NETWORK_CONFIG,
contractParameters: {
contractId: MOCKED_CONTRACT_ID,
},
})

await expect(() =>
contractEngine.readFromContract({
method: tokenMethods.name,
methodArgs: {},
...MOCKED_TX_INVOCATION,
})
).rejects.toThrow(CEError.missingSpec())
})
})

describe('Initialization workflow', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/stellar-plus/core/contract-engine/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { EnvelopeHeader, FeeBumpHeader, NetworkConfig, TransactionInvocation } f
export type ContractEngineConstructorArgs = {
networkConfig: NetworkConfig
contractParameters: {
spec: ContractSpec
spec?: ContractSpec
contractId?: string
wasm?: Buffer
wasmHash?: string
Expand Down
3 changes: 3 additions & 0 deletions src/stellar-plus/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ContractSpec } from '@stellar/stellar-sdk'

import { ContractEngine } from './contract-engine'
import { BuildTransactionPipeline } from './pipelines/build-transaction'
import { ClassicSignRequirementsPipeline } from './pipelines/classic-sign-requirements'
Expand All @@ -22,4 +24,5 @@ export const Core = {
SubmitTransaction: SubmitTransactionPipeline,
},
ContractEngine: ContractEngine,
ContractSpec,
}

0 comments on commit 38b68db

Please sign in to comment.