Skip to content

Commit

Permalink
Upgrade to edge-core-js v2.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
swansontec authored and samholmes committed May 14, 2024
1 parent 9feaed5 commit 62a8487
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 38 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"base-x": "^4.0.0",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"edge-core-js": "^1.14.0",
"edge-core-js": "^2.5.0",
"eslint": "^7.14.0",
"eslint-config-standard-kit": "0.15.1",
"eslint-plugin-import": "^2.22.1",
Expand Down
7 changes: 6 additions & 1 deletion src/common/utxobased/db/Processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ interface FetchTransactionArgs {
blockHeight?: number
blockHeightMax?: number
txId?: string
options?: EdgeGetTransactionsOptions
options?: EdgeGetTransactionsOptions & {
endDate?: Date
startDate?: Date
startEntries?: number
startIndex?: number
}
}

interface FetchUtxosArgs {
Expand Down
10 changes: 5 additions & 5 deletions src/common/utxobased/engine/UtxoEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { asMaybe } from 'cleaners'
import { makeMemoryDisklet } from 'disklet'
import {
DustSpendError,
EdgeCurrencyCodeOptions,
EdgeCurrencyEngine,
EdgeDataDump,
EdgeFreshAddress,
Expand All @@ -12,6 +11,7 @@ import {
EdgePaymentProtocolInfo,
EdgeSignMessageOptions,
EdgeSpendInfo,
EdgeTokenIdOptions,
EdgeTokenInfo,
EdgeTransaction,
InsufficientFundsError,
Expand Down Expand Up @@ -367,7 +367,7 @@ export async function makeUtxoEngine(
pluginState.removeEngine(engineState)
},

getBalance(_opts: EdgeCurrencyCodeOptions): string {
getBalance(_opts: EdgeTokenIdOptions): string {
return metadata.state.balance
},

Expand Down Expand Up @@ -463,7 +463,7 @@ export async function makeUtxoEngine(
return await engineState.getFreshAddress({ forceIndex })
},

getNumTransactions(_opts: EdgeCurrencyCodeOptions): number {
getNumTransactions(_opts: EdgeTokenIdOptions): number {
return processor.numTransactions()
},

Expand Down Expand Up @@ -543,7 +543,7 @@ export async function makeUtxoEngine(
bs.gt(totalAmountToSend, `${sumUtxos(utxos)}`) ||
utxos.length === 0
) {
throw new InsufficientFundsError(currencyInfo.currencyCode)
throw new InsufficientFundsError({ tokenId: null })
}

let targets: MakeTxTarget[] = []
Expand Down Expand Up @@ -949,7 +949,7 @@ export async function makeUtxoEngine(
if (tmpUtxos === null || tmpUtxos.length < 1) {
throw new Error('Private key has no funds')
}
const destAddress = await this.getFreshAddress({})
const destAddress = await this.getFreshAddress({ tokenId: null })
const nativeAmount = tmpMetadata.state.balance
const txOptions: TxOptions = { utxos: tmpUtxos, subtractFee: true }
spendInfo.spendTargets = [
Expand Down
2 changes: 1 addition & 1 deletion src/common/utxobased/keymanager/keymanager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ export function makeTx(args: MakeTxArgs): MakeTxReturn {
// This is how much fee is needed to validate the spend
const feeDelta = result.fee - (inputsValue - targetsValue)
throw new InsufficientFundsErrorPlus({
currencyCode: args.currencyCode,
tokenId: null,
networkFee: result.fee.toString(),
networkFeeShortage: feeDelta.toString()
})
Expand Down
7 changes: 4 additions & 3 deletions src/common/utxobased/keymanager/types.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { Cleaner } from 'cleaners'
import { InsufficientFundsError } from 'edge-core-js/types'
import { EdgeTokenId, InsufficientFundsError } from 'edge-core-js/types'

interface InsufficientFundsErrorOptsPlus {
// The currency we need more of:
currencyCode?: string
tokenId: EdgeTokenId
// If we don't have enough funds for a token send:
networkFee?: string

networkFeeShortage?: string
}
export class InsufficientFundsErrorPlus extends InsufficientFundsError {
networkFeeShortage?: string
constructor(opts: InsufficientFundsErrorOptsPlus = {}) {
constructor(opts: InsufficientFundsErrorOptsPlus) {
super(opts)
const { networkFeeShortage } = opts
this.networkFeeShortage = networkFeeShortage
Expand Down
1 change: 1 addition & 0 deletions test/common/plugin/CurrencyPlugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe('currencyPlugins.spec', () => {
const fakeIo = makeFakeIo()
const pluginOpts: EdgeCorePluginOptions = {
initOptions: {},
infoPayload: {},
io: {
...fakeIo,
random: () => Uint8Array.from(fixture.key)
Expand Down
21 changes: 18 additions & 3 deletions test/common/utxobased/db/Processor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -589,16 +589,25 @@ describe('Processor transactions tests', () => {
expect(tx3?.ourIns[0]).to.eqls('0')
expect(tx3?.ourAmount).to.eqls('1')

const [tx4] = await processor.fetchTransactions({ options: {} })
const [tx4] = await processor.fetchTransactions({
options: {
tokenId: null
}
})
expect(tx4).not.to.be.undefined

const results = await processor.fetchTransactions({
options: { startDate: new Date(11_000), endDate: new Date(15_000) }
options: {
tokenId: null,
startDate: new Date(11_000),
endDate: new Date(15_000)
}
})
expect(results).to.deep.equal([])

const [tx6] = await processor.fetchTransactions({
options: {
tokenId: null,
startDate: new Date(9_000),
endDate: new Date(15_000)
}
Expand Down Expand Up @@ -693,11 +702,16 @@ describe('Processor transactions tests', () => {
expect(tx3?.ourIns[0]).to.eqls('0')
expect(tx3?.ourAmount).to.eqls('1')

const [tx4] = await processor.fetchTransactions({ options: {} })
const [tx4] = await processor.fetchTransactions({
options: {
tokenId: null
}
})
expect(tx4).not.to.be.undefined

const [tx5] = await processor.fetchTransactions({
options: {
tokenId: null,
startDate: new Date(11_000),
endDate: new Date(20_000)
}
Expand All @@ -706,6 +720,7 @@ describe('Processor transactions tests', () => {

const tx6 = await processor.fetchTransactions({
options: {
tokenId: null,
startDate: new Date(9_000),
endDate: new Date(21_000)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ export interface SpendTests {
}
const Spend: SpendTests = {
'low fee': {
tokenId: null,
networkFeeOption: 'low',
metadata: {
name: 'Transfer to College Fund',
category: 'Transfer:Wallet:College Fund'
},
currencyCode: 'TESTBTC',
spendTargets: [
{
publicAddress: '2MutAAY6tW2HEyrhSadT1aQhP4KdCAKkC74',
Expand All @@ -26,12 +26,12 @@ const Spend: SpendTests = {
]
},
'low standard fee': {
tokenId: null,
networkFeeOption: 'standard',
metadata: {
name: 'Transfer to College Fund',
category: 'Transfer:Wallet:College Fund'
},
currencyCode: 'TESTBTC',
spendTargets: [
{
publicAddress: '2MutAAY6tW2HEyrhSadT1aQhP4KdCAKkC74',
Expand All @@ -40,12 +40,12 @@ const Spend: SpendTests = {
]
},
'middle standard fee': {
tokenId: null,
networkFeeOption: 'standard',
metadata: {
name: 'Transfer to College Fund',
category: 'Transfer:Wallet:College Fund'
},
currencyCode: 'TESTBTC',
spendTargets: [
{
publicAddress: '2MutAAY6tW2HEyrhSadT1aQhP4KdCAKkC74',
Expand All @@ -54,12 +54,12 @@ const Spend: SpendTests = {
]
},
'high standard fee': {
tokenId: null,
networkFeeOption: 'standard',
metadata: {
name: 'Transfer to College Fund',
category: 'Transfer:Wallet:College Fund'
},
currencyCode: 'TESTBTC',
spendTargets: [
{
publicAddress: '2MutAAY6tW2HEyrhSadT1aQhP4KdCAKkC74',
Expand All @@ -72,12 +72,12 @@ const Spend: SpendTests = {
]
},
'high fee': {
tokenId: null,
networkFeeOption: 'high',
metadata: {
name: 'Transfer to College Fund',
category: 'Transfer:Wallet:College Fund'
},
currencyCode: 'TESTBTC',
spendTargets: [
{
publicAddress: '2MutAAY6tW2HEyrhSadT1aQhP4KdCAKkC74',
Expand All @@ -90,13 +90,13 @@ const Spend: SpendTests = {
]
},
'custom fee': {
tokenId: null,
networkFeeOption: 'custom',
customNetworkFee: { satPerByte: '1000' },
metadata: {
name: 'Transfer to College Fund',
category: 'Transfer:Wallet:College Fund'
},
currencyCode: 'TESTBTC',
spendTargets: [
{
publicAddress: '2MutAAY6tW2HEyrhSadT1aQhP4KdCAKkC74',
Expand All @@ -111,12 +111,12 @@ const Spend: SpendTests = {
}
const InsufficientFundsError: SpendTests = {
'an amount over the balance': {
tokenId: null,
networkFeeOption: 'high',
metadata: {
name: 'Transfer to College Fund',
category: 'Transfer:Wallet:College Fund'
},
currencyCode: 'TESTBTC',
spendTargets: [
{
publicAddress: '2MutAAY6tW2HEyrhSadT1aQhP4KdCAKkC74',
Expand All @@ -129,12 +129,12 @@ const InsufficientFundsError: SpendTests = {
]
},
'a really big amount': {
tokenId: null,
networkFeeOption: 'high',
metadata: {
name: 'Transfer to College Fund',
category: 'Transfer:Wallet:College Fund'
},
currencyCode: 'TESTBTC',
spendTargets: [
{
publicAddress: '2MutAAY6tW2HEyrhSadT1aQhP4KdCAKkC74',
Expand All @@ -150,6 +150,7 @@ const InsufficientFundsError: SpendTests = {
const Sweep: SpendTests = {
'low fee': {
spendTargets: [],
tokenId: null,
networkFeeOption: 'low',
metadata: {
name: 'Transfer to College Fund',
Expand All @@ -159,6 +160,7 @@ const Sweep: SpendTests = {
},
'low standard fee': {
spendTargets: [],
tokenId: null,
networkFeeOption: 'low',
metadata: {
name: 'Transfer to College Fund',
Expand All @@ -168,6 +170,7 @@ const Sweep: SpendTests = {
},
'high fee': {
spendTargets: [],
tokenId: null,
networkFeeOption: 'high',
metadata: {
name: 'Transfer to College Fund',
Expand All @@ -177,6 +180,7 @@ const Sweep: SpendTests = {
},
'custom fee': {
spendTargets: [],
tokenId: null,
networkFeeOption: 'custom',
customNetworkFee: { satPerByte: '1000' },
metadata: {
Expand Down
16 changes: 4 additions & 12 deletions test/common/utxobased/engine/engine.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
EdgeCurrencyPlugin,
EdgeCurrencyTools,
EdgeFetchFunction,
EdgeGetTransactionsOptions,
EdgeSpendInfo,
JsonObject,
makeFakeIo
Expand Down Expand Up @@ -58,6 +57,7 @@ describe('engine.spec', function () {
fetch: fetchHack
},
log: testLog,
infoPayload: {},
nativeIo: {},
pluginDisklet: fakeIoDisklet
}
Expand Down Expand Up @@ -286,30 +286,21 @@ describe('engine.spec', function () {
describe(`Get Transactions from Wallet type ${WALLET_TYPE}`, function () {
it('Should get number of transactions from cache', function () {
assert.equal(
engine.getNumTransactions({}),
engine.getNumTransactions({ tokenId: null }),
TX_AMOUNT,
`should have ${TX_AMOUNT} tx from cache`
)
})

it('Should get transactions from cache', async function () {
await engine.getTransactions({}).then(txs => {
await engine.getTransactions({ tokenId: null }).then(txs => {
assert.equal(
txs.length,
TX_AMOUNT,
`should have ${TX_AMOUNT} tx from cache`
)
})
})

it('Should get transactions from cache with options', async function () {
const options: EdgeGetTransactionsOptions = {
startIndex: 1,
startEntries: 2
}
const txs = await engine.getTransactions(options)
assert.equal(txs.length, 2, 'should have 2 tx from cache')
})
})

describe('Should Add Gap Limit Addresses', function () {
Expand Down Expand Up @@ -419,6 +410,7 @@ describe('engine.spec', function () {

it('Should fail since no spend target is given', async function () {
const spendInfo: EdgeSpendInfo = {
tokenId: null,
networkFeeOption: 'high',
metadata: {
name: 'Transfer to College Fund',
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3121,10 +3121,10 @@ ecc-jsbn@~0.1.1:
typeforce "^1.18.0"
wif "^2.0.6"

edge-core-js@^1.14.0:
version "1.14.0"
resolved "https://registry.yarnpkg.com/edge-core-js/-/edge-core-js-1.14.0.tgz#16569cf6a24b50e26e0105eca554bd041ce15a01"
integrity sha512-P2yGTyu4eqoFUHFnrmkemxJrFFezql+cL2ZZ01JDyRJFgeAwy9zlEmg1Aj4IgOq8hzoNUFTd68fKTVPZZRDKEA==
edge-core-js@^2.5.0:
version "2.5.0"
resolved "https://registry.yarnpkg.com/edge-core-js/-/edge-core-js-2.5.0.tgz#9dc013c4f59a7a3fb1c88880eb600c4ef3e44e4f"
integrity sha512-sY0lJDIECanLx/muNGRXz3BUcfd3c76gCFA2BZu/4coE2O5o5GK4QnNB64uKPw6XBNrLfDhP1IcrclHDDgcOUQ==
dependencies:
aes-js "^3.1.0"
base-x "^4.0.0"
Expand Down

0 comments on commit 62a8487

Please sign in to comment.