157 lines
4.2 KiB
TypeScript
157 lines
4.2 KiB
TypeScript
|
import { call, put, apply } from 'redux-saga/effects';
|
||
|
|
||
|
import { computeIndexingHash } from 'libs/transaction';
|
||
|
import * as actions from './actions';
|
||
|
import * as sagas from './sagas';
|
||
|
|
||
|
describe('Sign', () => {
|
||
|
describe('signLocalTransactionHandler*', () => {
|
||
|
const tx = 'tx';
|
||
|
const wallet = {
|
||
|
signRawTransaction: jest.fn()
|
||
|
};
|
||
|
const action: any = { tx, wallet };
|
||
|
const signedTransaction = new Buffer('signedTransaction');
|
||
|
const indexingHash = 'indexingHash';
|
||
|
|
||
|
const gen = sagas.signLocalTransactionHandler(action);
|
||
|
|
||
|
it('should apply wallet.signRawTransaction', () => {
|
||
|
expect(gen.next().value).toEqual(apply(wallet, wallet.signRawTransaction, [tx]));
|
||
|
});
|
||
|
|
||
|
it('should call computeIndexingHash', () => {
|
||
|
expect(gen.next(signedTransaction).value).toEqual(
|
||
|
call(computeIndexingHash, signedTransaction)
|
||
|
);
|
||
|
});
|
||
|
|
||
|
it('should put signLocalTransactionSucceeded', () => {
|
||
|
expect(gen.next(indexingHash).value).toEqual(
|
||
|
put(
|
||
|
actions.signLocalTransactionSucceeded({
|
||
|
signedTransaction,
|
||
|
indexingHash,
|
||
|
noVerify: false
|
||
|
})
|
||
|
)
|
||
|
);
|
||
|
});
|
||
|
|
||
|
it('should be done', () => {
|
||
|
expect(gen.next().done).toEqual(true);
|
||
|
});
|
||
|
});
|
||
|
|
||
|
describe('signWeb3TransactionHandler*', () => {
|
||
|
const tx = {
|
||
|
serialize: jest.fn
|
||
|
};
|
||
|
const action: any = { tx };
|
||
|
const serializedTransaction = new Buffer('tx');
|
||
|
const indexingHash = 'indexingHash';
|
||
|
|
||
|
const gen = sagas.signWeb3TransactionHandler(action);
|
||
|
|
||
|
it('should apply tx.serialize', () => {
|
||
|
expect(gen.next().value).toEqual(apply(tx, tx.serialize));
|
||
|
});
|
||
|
|
||
|
it('should call computeIndexingHash', () => {
|
||
|
expect(gen.next(serializedTransaction).value).toEqual(
|
||
|
call(computeIndexingHash, serializedTransaction)
|
||
|
);
|
||
|
});
|
||
|
|
||
|
it('should put signWeb3TransactionSucceeded', () => {
|
||
|
expect(gen.next(indexingHash).value).toEqual(
|
||
|
put(
|
||
|
actions.signWeb3TransactionSucceeded({
|
||
|
transaction: serializedTransaction,
|
||
|
indexingHash
|
||
|
})
|
||
|
)
|
||
|
);
|
||
|
});
|
||
|
|
||
|
it('should be done', () => {
|
||
|
expect(gen.next().done).toEqual(true);
|
||
|
});
|
||
|
});
|
||
|
});
|
||
|
describe('Signing', () => {
|
||
|
describe('signLocalTransactionHandler*', () => {
|
||
|
const tx = 'tx';
|
||
|
const wallet = {
|
||
|
signRawTransaction: jest.fn()
|
||
|
};
|
||
|
const action: any = { tx, wallet };
|
||
|
const signedTransaction = new Buffer('signedTransaction');
|
||
|
const indexingHash = 'indexingHash';
|
||
|
|
||
|
const gen = sagas.signLocalTransactionHandler(action);
|
||
|
|
||
|
it('should apply wallet.signRawTransaction', () => {
|
||
|
expect(gen.next().value).toEqual(apply(wallet, wallet.signRawTransaction, [tx]));
|
||
|
});
|
||
|
|
||
|
it('should call computeIndexingHash', () => {
|
||
|
expect(gen.next(signedTransaction).value).toEqual(
|
||
|
call(computeIndexingHash, signedTransaction)
|
||
|
);
|
||
|
});
|
||
|
|
||
|
it('should put signLocalTransactionSucceeded', () => {
|
||
|
expect(gen.next(indexingHash).value).toEqual(
|
||
|
put(
|
||
|
actions.signLocalTransactionSucceeded({
|
||
|
signedTransaction,
|
||
|
indexingHash,
|
||
|
noVerify: false
|
||
|
})
|
||
|
)
|
||
|
);
|
||
|
});
|
||
|
|
||
|
it('should be done', () => {
|
||
|
expect(gen.next().done).toEqual(true);
|
||
|
});
|
||
|
});
|
||
|
|
||
|
describe('signWeb3TransactionHandler*', () => {
|
||
|
const tx = {
|
||
|
serialize: jest.fn
|
||
|
};
|
||
|
const action: any = { tx };
|
||
|
const serializedTransaction = new Buffer('tx');
|
||
|
const indexingHash = 'indexingHash';
|
||
|
|
||
|
const gen = sagas.signWeb3TransactionHandler(action);
|
||
|
|
||
|
it('should apply tx.serialize', () => {
|
||
|
expect(gen.next().value).toEqual(apply(tx, tx.serialize));
|
||
|
});
|
||
|
|
||
|
it('should call computeIndexingHash', () => {
|
||
|
expect(gen.next(serializedTransaction).value).toEqual(
|
||
|
call(computeIndexingHash, serializedTransaction)
|
||
|
);
|
||
|
});
|
||
|
|
||
|
it('should put signWeb3TransactionSucceeded', () => {
|
||
|
expect(gen.next(indexingHash).value).toEqual(
|
||
|
put(
|
||
|
actions.signWeb3TransactionSucceeded({
|
||
|
transaction: serializedTransaction,
|
||
|
indexingHash
|
||
|
})
|
||
|
)
|
||
|
);
|
||
|
});
|
||
|
|
||
|
it('should be done', () => {
|
||
|
expect(gen.next().done).toEqual(true);
|
||
|
});
|
||
|
});
|
||
|
});
|