Skip to content

Commit

Permalink
test(abstract-eth): adding utils to src
Browse files Browse the repository at this point in the history
TICKET: COIN-1322
  • Loading branch information
MohammedRyaan786 committed Aug 26, 2024
1 parent b297c9a commit 51621bd
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 5 deletions.
1 change: 1 addition & 0 deletions modules/abstract-eth/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './abstractEthLikeCoin';
export * from './ethLikeToken';
export * from './lib';
export * from './abstractEthLikeNewCoins';
export * from './test-utils';
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
SignTransactionOptions,
TransferBuilder,
TransactionBuilder,
} from '../../src';
} from '../../../src';

nock.enableNetConnect();

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import should from 'should';
import { coins } from '@bitgo/statics';
import { Transaction } from '../../src';
import { Transaction } from '../../lib';
import Common from '@ethereumjs/common';

export function runTransactionTests(coinName: string, testData: any, common: Common) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import should from 'should';
import { TransactionType } from '@bitgo/sdk-core';
import { TransactionBuilder } from '../../../src';
import { TransactionBuilder } from '../../../lib';

export async function testAddressInitializationWithoutContractAddress(txBuilder: TransactionBuilder) {
it('should fail if there is no contract address', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { TransactionType, BaseTransaction } from '@bitgo/sdk-core';
import EthereumAbi from 'ethereumjs-abi';
import should from 'should';
import * as ethUtil from 'ethereumjs-util';
import { decodeTransferData, KeyPair, TransactionBuilder } from '../../../src';
import { decodeTransferData, KeyPair, TransactionBuilder } from '../../../lib';

export function runSendTests(coinName: string, txBuilder, getBuilder, testData) {
describe(`${coinName} transaction builder send`, () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import should from 'should';
import { TransactionType } from '@bitgo/sdk-core';
import { TransactionBuilder } from '../../../src';
import { TransactionBuilder } from '../../../lib';

function addOwner(txBuilder: TransactionBuilder, testData) {
txBuilder.owner(testData.ACCOUNT_1);
Expand Down
82 changes: 82 additions & 0 deletions modules/abstract-eth/src/test-utils/unit/transferBuilder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import assert from 'assert';
import should from 'should';
import { coins, EthereumNetwork as EthLikeNetwork } from '@bitgo/statics';
import { KeyPair, TransferBuilder } from '../../lib';

describe('Eth send multi sig builder', function () {
const toAddress = '0x7325A3F7d4f9E86AE62Cf742426078C3755730d5';
const xprv =
'xprv9s21ZrQH143K3D8TXfvAJgHVfTEeQNW5Ys9wZtnUZkqPzFzSjbEJrWC1vZ4GnXCvR7rQL2UFX3RSuYeU9MrERm1XBvACow7c36vnz5iYyj2';
const key = new KeyPair({ prv: xprv }).getKeys().prv as string;
const amount = '100000000000000000'; // equivalent to 0.1 ether
const ethLikeCoins = ['hteth', 'tarbeth', 'topeth', 'zketh'];

describe('should fail', () => {
it('should fail if a coin does not exists in @bitgo/statics', () => {
should(() => {
new TransferBuilder().coin('inexistentcoin');
}).throw();
});

ethLikeCoins.forEach((coin) => {
it('should fail with an invalid key', () => {
const staticsCoin = coins.get(coin) as unknown as EthLikeNetwork;
const builder = new TransferBuilder()
.coin(coin)
.expirationTime(1590078260)
.amount(amount)
.to(toAddress)
.contractSequenceId(2)
.key('invalidkey');
should(() => {
builder.signAndBuild(`${staticsCoin.chainId}`);
}).throw('private key length is invalid');
});
});

it('should fail with an invalid sequence id', () => {
should(() => {
new TransferBuilder().contractSequenceId(-1);
}).throw('Invalid contract sequence id');
});

it('should fail with an invalid destination address', () => {
should(() => {
new TransferBuilder().to('invalidaddress');
}).throw('Invalid address');
});

it('should fail with an invalid amount: text value', () => {
should(() => {
new TransferBuilder().amount('invalidamount');
}).throw('Invalid amount');
});

it('should fail with an invalid amount: negative value', () => {
should(() => {
new TransferBuilder().amount('-10');
}).throw('Invalid amount');
});

it('should fail with an invalid expiration time', () => {
should(() => {
new TransferBuilder().expirationTime(-1);
}).throw('Invalid expiration time');
});

it('should fail if a sequenceId param is missing', () => {
const builder = new TransferBuilder().amount(amount).to(toAddress).key(key);
assert.throws(() => builder.signAndBuild(''));
});

it('should fail if a destination param is missing', () => {
const builder = new TransferBuilder().amount(amount).contractSequenceId(2).key(key);
assert.throws(() => builder.signAndBuild(''));
});

it('should fail if a amount param is missing', () => {
const builder = new TransferBuilder().to(toAddress).contractSequenceId(2).key(key);
assert.throws(() => builder.signAndBuild(''));
});
});
});

0 comments on commit 51621bd

Please sign in to comment.