-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(sdk-coin-zketh): add test cases for zketh
Ticket: WIN-1422
- Loading branch information
Showing
10 changed files
with
850 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
import { BitGoBase } from '@bitgo/sdk-core'; | ||
import { Zketh } from './zketh'; | ||
import { Tzketh } from './tzketh'; | ||
import { ZkethToken } from './zkethToken'; | ||
|
||
export const register = (sdk: BitGoBase): void => { | ||
sdk.register('zketh', Zketh.createInstance); | ||
sdk.register('tzketh', Tzketh.createInstance); | ||
ZkethToken.createTokenConstructors().forEach(({ name, coinConstructor }) => { | ||
sdk.register(name, coinConstructor); | ||
}); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
export function getTxListRequest(address: string) { | ||
return { | ||
module: 'account', | ||
action: 'txlist', | ||
address: address, | ||
}; | ||
} | ||
|
||
export const getTxListResponse = { | ||
status: '0', | ||
message: 'No transactions found', | ||
result: [], | ||
}; | ||
|
||
export function getBalanceRequest(address: string) { | ||
return { | ||
module: 'account', | ||
action: 'balance', | ||
address: address, | ||
}; | ||
} | ||
|
||
export function getTokenBalanceRequest(tokenContractAddress: string, address: string) { | ||
return { | ||
module: 'account', | ||
action: 'tokenbalance', | ||
contractaddress: tokenContractAddress, | ||
address: address, | ||
tag: 'latest', | ||
}; | ||
} | ||
|
||
export const getBalanceResponse = { | ||
status: '1', | ||
message: 'OK', | ||
result: '9999999999999999928', | ||
}; | ||
|
||
export const getContractCallRequest = { | ||
module: 'proxy', | ||
action: 'eth_call', | ||
to: '0xdf07117705a9f8dc4c2a78de66b7f1797dba9d4e', | ||
data: 'a0b7967b', | ||
tag: 'latest', | ||
}; | ||
|
||
export const getContractCallResponse = { | ||
jsonrpc: '2.0', | ||
result: '0x0000000000000000000000000000000000000000000000000000000000002a7f', | ||
id: 1, | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { BaseBuilder } from '@bitgo/sdk-core'; | ||
import { coins } from '@bitgo/statics'; | ||
import { TransactionBuilder } from '../src'; | ||
|
||
export function getBuilder(coinName: string): BaseBuilder { | ||
return new TransactionBuilder(coins.get(coinName)); | ||
} |
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import should from 'should'; | ||
import { coins } from '@bitgo/statics'; | ||
import { Transaction } from '../../src'; | ||
import { getCommon } from '../../src/lib/utils'; | ||
import * as testData from '../resources'; | ||
|
||
describe('Zketh Transaction', () => { | ||
const coinConfig = coins.get('tzketh'); | ||
const common = getCommon(coinConfig.network.type); | ||
|
||
/** | ||
* return a new transaction object | ||
*/ | ||
function getTransaction(): Transaction { | ||
return new Transaction(coinConfig, common); | ||
} | ||
|
||
describe('should throw ', () => { | ||
it('an empty transaction', () => { | ||
const tx = getTransaction(); | ||
should.throws(() => { | ||
tx.toJson(); | ||
}); | ||
should.throws(() => { | ||
tx.toBroadcastFormat(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('should return', () => { | ||
it('a valid transaction', () => { | ||
const tx = getTransaction(); | ||
tx.setTransactionData(testData.TXDATA); | ||
should.deepEqual(tx.toJson(), testData.TXDATA); | ||
should.equal(tx.toBroadcastFormat(), testData.UNSIGNED_TX); | ||
}); | ||
}); | ||
|
||
describe('should sign', () => { | ||
it('invalid', () => { | ||
const tx = getTransaction(); | ||
return tx.sign(testData.KEYPAIR_PRV).should.be.rejected(); | ||
}); | ||
|
||
it('valid', () => { | ||
const tx = getTransaction(); | ||
tx.setTransactionData(testData.TXDATA); | ||
return tx.sign(testData.KEYPAIR_PRV).should.be.fulfilled(); | ||
}); | ||
}); | ||
|
||
describe('should return encoded tx', () => { | ||
it('valid sign', async function () { | ||
const tx = getTransaction(); | ||
tx.setTransactionData(testData.TXDATA); | ||
await tx.sign(testData.KEYPAIR_PRV); | ||
should.equal(tx.toBroadcastFormat(), testData.ENCODED_TRANSACTION); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.