Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: consolidate core/Ogmios/util into core Cardano and Asset mo…
…dules
- Loading branch information
1 parent
b231031
commit ee7108e
Showing
11 changed files
with
75 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,15 @@ | ||
import { Asset, BigIntMath } from '..'; | ||
import { Value } from './types'; | ||
|
||
/** | ||
* Blockchain restriction for minimum coin quantity in a UTxO | ||
*/ | ||
export const computeMinUtxoValue = (coinsPerUtxoWord: bigint): bigint => coinsPerUtxoWord * 29n; | ||
|
||
/** | ||
* Sum all quantities | ||
*/ | ||
export const coalesceValueQuantities = (quantities: Value[]): Value => ({ | ||
coins: BigIntMath.sum(quantities.map(({ coins }) => coins)), | ||
assets: Asset.util.coalesceTokenMaps(quantities.map(({ assets }) => assets)) | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,40 @@ | ||
import { computeMinUtxoValue } from '../../src/Cardano/util'; | ||
import * as Cardano from '../../src/Cardano'; | ||
|
||
describe('Cardano', () => { | ||
describe('util', () => { | ||
it('computeMinUtxoValue', () => expect(typeof computeMinUtxoValue(100n)).toBe('bigint')); | ||
it('computeMinUtxoValue', () => expect(typeof Cardano.util.computeMinUtxoValue(100n)).toBe('bigint')); | ||
|
||
describe('coalesceValueQuantities', () => { | ||
it('coin only', () => { | ||
const q1: Cardano.Value = { coins: 50n }; | ||
const q2: Cardano.Value = { coins: 100n }; | ||
expect(Cardano.util.coalesceValueQuantities([q1, q2])).toEqual({ coins: 150n }); | ||
}); | ||
it('coin and assets', () => { | ||
const TSLA_Asset = 'b32_1vk0jj9lmv0cjkvmxw337u467atqcgkauwd4eczaugzagyghp25lTSLA'; | ||
const PXL_Asset = 'b32_1rmy9mnhz0ukepmqlng0yee62ve7un05trpzxxg3lnjtqzp4dmmrPXL'; | ||
const q1: Cardano.Value = { | ||
coins: 50n, | ||
assets: { | ||
[TSLA_Asset]: 50n, | ||
[PXL_Asset]: 100n | ||
} | ||
}; | ||
const q2: Cardano.Value = { coins: 100n }; | ||
const q3: Cardano.Value = { | ||
coins: 20n, | ||
assets: { | ||
[TSLA_Asset]: 20n | ||
} | ||
}; | ||
expect(Cardano.util.coalesceValueQuantities([q1, q2, q3])).toEqual({ | ||
coins: 170n, | ||
assets: { | ||
[TSLA_Asset]: 70n, | ||
[PXL_Asset]: 100n | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.