Skip to content

Commit

Permalink
update txType in PaymentTransaction model
Browse files Browse the repository at this point in the history
  • Loading branch information
RaaCT0R committed Aug 14, 2023
1 parent 3479baf commit f8d81ec
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 25 deletions.
2 changes: 1 addition & 1 deletion packages/abstract-chain/lib/AbstractChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ abstract class AbstractChain {
*/
abstract generateTransaction: (
eventId: string,
txType: string,
txType: TransactionType,
order: PaymentOrder,
unsignedTransactions: PaymentTransaction[],
serializedSignedTransactions: string[],
Expand Down
2 changes: 1 addition & 1 deletion packages/abstract-chain/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ interface PaymentTransaction {
txId: string;
eventId: string;
txBytes: Uint8Array;
txType: string;
txType: TransactionType;
}

interface PaymentTransactionJsonModel {
Expand Down
9 changes: 7 additions & 2 deletions packages/abstract-chain/tests/AbstractChain.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import TestChain from './TestChain';
import TestChainNetwork from './network/TestChainNetwork';
import { AssetBalance, ChainConfigs, PaymentTransaction } from '../lib';
import {
AssetBalance,
ChainConfigs,
PaymentTransaction,
TransactionType,
} from '../lib';
import { when } from 'jest-when';

const spyOn = jest.spyOn;
Expand Down Expand Up @@ -28,7 +33,7 @@ describe('AbstractChain', () => {
txId: 'mockedTxId',
eventId: 'mockedNetworkId',
txBytes: Buffer.from('mockedTxBytes'),
txType: 'payment',
txType: TransactionType.payment,
};
const network = new TestChainNetwork();

Expand Down
2 changes: 1 addition & 1 deletion packages/chains/cardano/lib/CardanoChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class CardanoChain extends AbstractUtxoChain<CardanoUtxo> {
*/
generateTransaction = async (
eventId: string,
txType: string,
txType: TransactionType,
order: PaymentOrder,
unsignedTransactions: PaymentTransaction[],
serializedSignedTransactions: string[]
Expand Down
15 changes: 9 additions & 6 deletions packages/chains/cardano/lib/CardanoTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import { PaymentTransaction } from '@rosen-chains/abstract-chain';
import {
PaymentTransaction,
PaymentTransactionJsonModel,
TransactionType,
} from '@rosen-chains/abstract-chain';
import { CARDANO_CHAIN } from './constants';
import * as JSONBigInt from 'json-bigint';

class CardanoTransaction implements PaymentTransaction {
eventId: string;
network: string;
txBytes: Uint8Array;
txId: string;
txType: string;
txType: TransactionType;

constructor(
eventId: string,
txBytes: Uint8Array,
txId: string,
txType: string
txType: TransactionType
) {
this.network = CARDANO_CHAIN;
this.eventId = eventId;
Expand All @@ -27,12 +30,12 @@ class CardanoTransaction implements PaymentTransaction {
* @returns CardanoTransaction object
*/
static fromJson = (jsonString: string): CardanoTransaction => {
const obj = JSON.parse(jsonString);
const obj = JSON.parse(jsonString) as PaymentTransactionJsonModel;
return new CardanoTransaction(
obj.eventId,
Buffer.from(obj.txBytes, 'hex'),
obj.txId,
obj.txType
obj.txType as TransactionType
);
};

Expand Down
6 changes: 3 additions & 3 deletions packages/chains/cardano/tests/CardanoChain.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ describe('CardanoChain', () => {
// call the function
const result = await cardanoChain.generateTransaction(
'2bedc6e54ede7748e5efc7df689a0a89b281ac1d92d09054650d5f27a25d5b85',
'payment',
TransactionType.payment,
order,
[],
[]
Expand Down Expand Up @@ -236,7 +236,7 @@ describe('CardanoChain', () => {
await expect(async () => {
await cardanoChain.generateTransaction(
'event1',
'type1',
TransactionType.payment,
TestData.transaction1Order,
[],
[]
Expand Down Expand Up @@ -272,7 +272,7 @@ describe('CardanoChain', () => {
await expect(async () => {
await cardanoChain.generateTransaction(
'event1',
'type1',
TransactionType.payment,
TestData.transaction1Order,
[],
[]
Expand Down
2 changes: 1 addition & 1 deletion packages/chains/ergo/lib/ErgoChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class ErgoChain extends AbstractUtxoChain<wasm.ErgoBox> {
*/
generateTransaction = async (
eventId: string,
txType: string,
txType: TransactionType,
order: PaymentOrder,
unsignedTransactions: PaymentTransaction[],
serializedSignedTransactions: string[],
Expand Down
11 changes: 7 additions & 4 deletions packages/chains/ergo/lib/ErgoTransaction.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { PaymentTransaction } from '@rosen-chains/abstract-chain';
import {
PaymentTransaction,
TransactionType,
} from '@rosen-chains/abstract-chain';
import { ERGO_CHAIN } from './constants';
import { ErgoTransactionJsonModel } from './types';

Expand All @@ -7,7 +10,7 @@ class ErgoTransaction implements PaymentTransaction {
txId: string;
eventId: string;
txBytes: Uint8Array;
txType: string;
txType: TransactionType;
inputBoxes: Array<Uint8Array>;
dataInputs: Array<Uint8Array>;

Expand All @@ -17,7 +20,7 @@ class ErgoTransaction implements PaymentTransaction {
txBytes: Uint8Array,
inputBoxes: Array<Uint8Array>,
dataInputs: Array<Uint8Array>,
txType: string
txType: TransactionType
) {
this.network = ERGO_CHAIN;
this.txId = txId;
Expand All @@ -40,7 +43,7 @@ class ErgoTransaction implements PaymentTransaction {
Buffer.from(obj.txBytes, 'hex'),
obj.inputBoxes.map((box) => Buffer.from(box, 'hex')),
obj.dataInputs.map((box) => Buffer.from(box, 'hex')),
obj.txType
obj.txType as TransactionType
);
};

Expand Down
12 changes: 6 additions & 6 deletions packages/chains/ergo/tests/ErgoChain.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ describe('ErgoChain', () => {
).sigma_serialize_bytes(),
[],
[],
'txType'
TransactionType.payment
);

// mock a config that has more fee comparing to mocked transaction fee
Expand Down Expand Up @@ -720,7 +720,7 @@ describe('ErgoChain', () => {
).sigma_serialize_bytes(),
[],
[],
'txType'
TransactionType.payment
);

// mock a config that has less fee comparing to mocked transaction fee
Expand Down Expand Up @@ -1404,7 +1404,7 @@ describe('ErgoChain', () => {
.sigma_serialize_bytes(),
[],
[],
'txType'
TransactionType.payment
);

// run test
Expand Down Expand Up @@ -1449,7 +1449,7 @@ describe('ErgoChain', () => {
.sigma_serialize_bytes(),
[],
[],
'txType'
TransactionType.payment
);

// run test
Expand Down Expand Up @@ -1487,7 +1487,7 @@ describe('ErgoChain', () => {
).sigma_serialize_bytes(),
[],
[],
'txType'
TransactionType.payment
);

// run test
Expand Down Expand Up @@ -1545,7 +1545,7 @@ describe('ErgoChain', () => {
).sigma_serialize_bytes(),
[],
[],
'txType'
TransactionType.payment
);

// run test & check thrown exception
Expand Down

0 comments on commit f8d81ec

Please sign in to comment.