Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update for new proto format #3

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8,180 changes: 8,163 additions & 17 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@
},
"dependencies": {
"@bithighlander/bitcoin-cash-js-lib": "^5.2.1",
"@cosmjs/proto-signing": "^0.27.1",
"@cosmjs/stargate": "^0.27.1",
"@pioneer-platform/loggerdog": "^8.0.1",
"@pioneer-platform/osmosis-tx-codecs": "^8.1.19",
"@pioneer-platform/pioneer-coins": "^8.1.19",
"@shapeshiftoss/hdwallet-core": "latest",
"@types/node": "^15.0.2",
"bip39": "^3.0.4",
"codeclimate-test-reporter": "^0.5.1",
"cosmjs-types": "^0.4.1",
"fiosdk-offline": "^1.2.21",
"google-protobuf": "^3.17.0"
}
Expand Down
187 changes: 173 additions & 14 deletions src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {sign,createSignedTx} from '../src/index';
import {sign} from '../src/index';
let {
SLIP_44_BY_LONG,
bip32ToAddressNList
Expand All @@ -12,19 +12,180 @@ const log = require("@pioneer-platform/loggerdog")()

const supported_assets = [
'cosmos',
'thorchain',
'terra',
'kava',
'secret',
'osmosis'
'osmosis',
// 'thorchain',
// 'terra',
// 'kava',
// 'secret',

]

let prefixs = {
'osmosis':'osmo',
'cosmos':'cosmos'
}

const REFERENCE_SEED = "alcohol woman abuse must during monitor noble actual mixed trade anger aisle"

describe('signs Tendermint transactions', async function() {
let tag = ' | sign | '
let asset = 'osmosis'
for(let i = 0; i < supported_assets.length; i++){
let asset = supported_assets[i]
console.log("ASSET: ",asset)

//Osmosis only
// if(asset === 'osmosis'){
// it('signs a mainnet '+asset+' reference swap transaction', async function() {
// //get reference data
// let referenceTx = fs.readFileSync('./src/reference-data/defi/tx01.mainnet.'+asset+'.swap.json');
// referenceTx = JSON.parse(referenceTx.toString())
//
// let referenceTxSigned = fs.readFileSync('./src/reference-data/staking/tx01.mainnet.'+asset+'.swap.signed.json');
// referenceTxSigned = JSON.parse(referenceTxSigned.toString())
//
// // log.info(tag,"referenceTx: ",referenceTx)
// // log.info(tag,"referenceTxSigned: ",referenceTxSigned)
// expect(referenceTx).toBeTruthy();
// expect(referenceTxSigned).toBeTruthy();
//
// const network = getNetwork(asset);
// const wallet = bitcoin.bip32.fromSeed(await mnemonicToSeed(REFERENCE_SEED), network);
//
// const masterPath = bip32ToAddressNList("m/44'/"+SLIP_44_BY_LONG[asset].toString()+"'/0'/0/0")
// log.info(tag,"masterPath: ",masterPath)
// // const keyPair = util.getKeyPair(wallet, masterPath, asset);
// // log.info(tag,"keyPair: ",keyPair)
// // @ts-ignore
// let prefix = prefixs[asset]
// const result = await sign(referenceTx, REFERENCE_SEED, referenceTx.sequence, referenceTx.account_number, referenceTx.chain_id, prefix);
// log.info(tag,"result: ",result)
//
//
// expect(result.serialized).toBe(referenceTxSigned.serialized);
// expect(result.signatures[0]).toBe(referenceTxSigned.signatures[0]);
// });
// }

it('signs a mainnet '+asset+' reference undelegate transaction', async function() {
//get reference data
let referenceTx = fs.readFileSync('./src/reference-data/staking/tx01.mainnet.'+asset+'.undelegate.json');
referenceTx = JSON.parse(referenceTx.toString())

let referenceTxSigned = fs.readFileSync('./src/reference-data/staking/tx01.mainnet.'+asset+'.undelegate.signed.json');
referenceTxSigned = JSON.parse(referenceTxSigned.toString())

// log.info(tag,"referenceTx: ",referenceTx)
// log.info(tag,"referenceTxSigned: ",referenceTxSigned)
expect(referenceTx).toBeTruthy();
expect(referenceTxSigned).toBeTruthy();

const network = getNetwork(asset);
const wallet = bitcoin.bip32.fromSeed(await mnemonicToSeed(REFERENCE_SEED), network);

const masterPath = bip32ToAddressNList("m/44'/"+SLIP_44_BY_LONG[asset].toString()+"'/0'/0/0")
log.info(tag,"masterPath: ",masterPath)
// const keyPair = util.getKeyPair(wallet, masterPath, asset);
// log.info(tag,"keyPair: ",keyPair)
// @ts-ignore
let prefix = prefixs[asset]
const result = await sign(referenceTx, REFERENCE_SEED, referenceTx.sequence, referenceTx.account_number, referenceTx.chain_id, prefix);
log.info(tag,"result: ",result)


expect(result.serialized).toBe(referenceTxSigned.serialized);
expect(result.signatures[0]).toBe(referenceTxSigned.signatures[0]);
});

it('signs a mainnet '+asset+' reference claim rewards transaction', async function() {
//get reference data
let referenceTx = fs.readFileSync('./src/reference-data/staking/tx01.mainnet.'+asset+'.rewards.json');
referenceTx = JSON.parse(referenceTx.toString())

let referenceTxSigned = fs.readFileSync('./src/reference-data/staking/tx01.mainnet.'+asset+'.rewards.signed.json');
referenceTxSigned = JSON.parse(referenceTxSigned.toString())

// log.info(tag,"referenceTx: ",referenceTx)
// log.info(tag,"referenceTxSigned: ",referenceTxSigned)
expect(referenceTx).toBeTruthy();
expect(referenceTxSigned).toBeTruthy();

const network = getNetwork(asset);
const wallet = bitcoin.bip32.fromSeed(await mnemonicToSeed(REFERENCE_SEED), network);

const masterPath = bip32ToAddressNList("m/44'/"+SLIP_44_BY_LONG[asset].toString()+"'/0'/0/0")
log.info(tag,"masterPath: ",masterPath)
// const keyPair = util.getKeyPair(wallet, masterPath, asset);
// log.info(tag,"keyPair: ",keyPair)
// @ts-ignore
let prefix = prefixs[asset]
const result = await sign(referenceTx, REFERENCE_SEED, referenceTx.sequence, referenceTx.account_number, referenceTx.chain_id, prefix);
log.info(tag,"result: ",result)


expect(result.serialized).toBe(referenceTxSigned.serialized);
expect(result.signatures[0]).toBe(referenceTxSigned.signatures[0]);
});

it('signs a mainnet '+asset+' reference redelegate transaction', async function() {
//get reference data
let referenceTx = fs.readFileSync('./src/reference-data/staking/tx01.mainnet.'+asset+'.redelegate.json');
referenceTx = JSON.parse(referenceTx.toString())

let referenceTxSigned = fs.readFileSync('./src/reference-data/staking/tx01.mainnet.'+asset+'.redelegate.signed.json');
referenceTxSigned = JSON.parse(referenceTxSigned.toString())

// log.info(tag,"referenceTx: ",referenceTx)
// log.info(tag,"referenceTxSigned: ",referenceTxSigned)
expect(referenceTx).toBeTruthy();
expect(referenceTxSigned).toBeTruthy();

const network = getNetwork(asset);
const wallet = bitcoin.bip32.fromSeed(await mnemonicToSeed(REFERENCE_SEED), network);

const masterPath = bip32ToAddressNList("m/44'/"+SLIP_44_BY_LONG[asset].toString()+"'/0'/0/0")
log.info(tag,"masterPath: ",masterPath)
// const keyPair = util.getKeyPair(wallet, masterPath, asset);
// log.info(tag,"keyPair: ",keyPair)
// @ts-ignore
let prefix = prefixs[asset]
const result = await sign(referenceTx, REFERENCE_SEED, referenceTx.sequence, referenceTx.account_number, referenceTx.chain_id, prefix);
log.info(tag,"result: ",result)


expect(result.serialized).toBe(referenceTxSigned.serialized);
expect(result.signatures[0]).toBe(referenceTxSigned.signatures[0]);
});

it('signs a mainnet '+asset+' reference delegate transaction', async function() {
//get reference data
let referenceTx = fs.readFileSync('./src/reference-data/staking/tx01.mainnet.'+asset+'.delegate.json');
referenceTx = JSON.parse(referenceTx.toString())

let referenceTxSigned = fs.readFileSync('./src/reference-data/staking/tx01.mainnet.'+asset+'.delegate.signed.json');
referenceTxSigned = JSON.parse(referenceTxSigned.toString())

// log.info(tag,"referenceTx: ",referenceTx)
// log.info(tag,"referenceTxSigned: ",referenceTxSigned)
expect(referenceTx).toBeTruthy();
expect(referenceTxSigned).toBeTruthy();

const network = getNetwork(asset);
const wallet = bitcoin.bip32.fromSeed(await mnemonicToSeed(REFERENCE_SEED), network);

const masterPath = bip32ToAddressNList("m/44'/"+SLIP_44_BY_LONG[asset].toString()+"'/0'/0/0")
log.info(tag,"masterPath: ",masterPath)
// const keyPair = util.getKeyPair(wallet, masterPath, asset);
// log.info(tag,"keyPair: ",keyPair)
// @ts-ignore
let prefix = prefixs[asset]
const result = await sign(referenceTx, REFERENCE_SEED, referenceTx.sequence, referenceTx.account_number, referenceTx.chain_id, prefix);
log.info(tag,"result: ",result)


expect(result.serialized).toBe(referenceTxSigned.serialized);
expect(result.signatures[0]).toBe(referenceTxSigned.signatures[0]);
});

it('signs a mainnet '+asset+' reference transfer transaction', async function() {
//get reference data
Expand All @@ -46,17 +207,15 @@ describe('signs Tendermint transactions', async function() {
log.info(tag,"masterPath: ",masterPath)
// const keyPair = util.getKeyPair(wallet, masterPath, asset);
// log.info(tag,"keyPair: ",keyPair)

const result = await sign(referenceTx, wallet, referenceTx.sequence, referenceTx.account_number, referenceTx.chain_id);
// @ts-ignore
let prefix = prefixs[asset]
const result = await sign(referenceTx, REFERENCE_SEED, referenceTx.sequence, referenceTx.account_number, referenceTx.chain_id, prefix);
log.info(tag,"result: ",result)
const SignedTx = await createSignedTx(referenceTx, result);
log.info(tag,"SignedTx: ",SignedTx)

expect(SignedTx.signatures[0].signature).toBe(referenceTxSigned.signatures[0].signature);
});

//TODO testnets

expect(result.serialized).toBe(referenceTxSigned.serialized);
expect(result.signatures[0]).toBe(referenceTxSigned.signatures[0]);
});
}


Expand Down
Loading