Fix create bond message

This commit is contained in:
nabarun 2022-04-01 09:01:00 +05:30 committed by Ashwin Phatak
parent 4c3a3558d3
commit 6bb264d69c
4 changed files with 166 additions and 10 deletions

View File

@ -75,3 +75,9 @@ Follow these steps to run the tests:
# Check votes tally
ethermintd query gov tally 1
```
- Check bonds list:
```bash
ethermintd query bond list
```

View File

@ -17,9 +17,21 @@ import * as coin from './proto/cosmos/base/v1beta1/coin'
const MSG_CREATE_BOND_TYPES = {
MsgValue: [
{ name: 'signer', type: 'string' },
{ name: 'coins', type: 'TypeCoin[]' },
{ name: 'coins', type: 'TypeCoins[]' },
],
TypeCoin: [
TypeCoins: [
{ name: 'denom', type: 'string' },
{ name: 'amount', type: 'string' },
],
}
const MSG_REFILL_BOND_TYPES = {
MsgValue: [
{ name: 'id', type: 'string' },
{ name: 'signer', type: 'string' },
{ name: 'coins', type: 'TypeCoins[]' },
],
TypeCoins: [
{ name: 'denom', type: 'string' },
{ name: 'amount', type: 'string' },
],
@ -30,6 +42,12 @@ export interface MessageMsgCreateBond {
denom: string
}
export interface MessageMsgRefillBond {
id: string,
amount: string
denom: string
}
export function createTxMsgCreateBond(
chain: Chain,
sender: Sender,
@ -89,6 +107,67 @@ export function createTxMsgCreateBond(
}
}
export function createTxMsgRefillBond(
chain: Chain,
sender: Sender,
fee: Fee,
memo: string,
params: MessageMsgRefillBond,
) {
// EIP712
const feeObject = generateFee(
fee.amount,
fee.denom,
fee.gas,
sender.accountAddress,
)
const types = generateTypes(MSG_REFILL_BOND_TYPES)
const msg = createMsgRefillBond(
params.id,
sender.accountAddress,
params.amount,
params.denom
)
const messages = generateMessage(
sender.accountNumber.toString(),
sender.sequence.toString(),
chain.cosmosChainId,
memo,
feeObject,
msg,
)
const eipToSign = createEIP712(types, chain.chainId, messages)
// Cosmos
const msgCosmos = protoCreateMsgRefillBond(
params.id,
sender.accountAddress,
params.amount,
params.denom
)
const tx = createTransaction(
msgCosmos,
memo,
fee.amount,
fee.denom,
parseInt(fee.gas, 10),
'ethsecp256',
sender.pubkey,
sender.sequence,
sender.accountNumber,
chain.cosmosChainId,
)
return {
signDirect: tx.signDirect,
legacyAmino: tx.legacyAmino,
eipToSign,
}
}
function createMsgCreateBond(
signer: string,
amount: string,
@ -97,13 +176,13 @@ function createMsgCreateBond(
return {
type: 'bond/MsgCreateBond',
value: {
signer,
coins: [
{
amount,
denom,
},
],
signer
},
}
}
@ -118,13 +197,57 @@ const protoCreateMsgCreateBond = (
amount,
})
const depositMessage = new bondTx.vulcanize.bond.v1beta1.MsgCreateBond({
const createBondMessage = new bondTx.vulcanize.bond.v1beta1.MsgCreateBond({
signer,
coins: [value]
})
return {
message: depositMessage,
message: createBondMessage,
path: 'vulcanize.bond.v1beta1.MsgCreateBond',
}
}
function createMsgRefillBond(
id: string,
signer: string,
amount: string,
denom: string,
) {
return {
type: 'bond/MsgRefillBond',
value: {
coins: [
{
amount,
denom,
},
],
id,
signer
},
}
}
const protoCreateMsgRefillBond = (
id: string,
signer: string,
amount: string,
denom: string,
) => {
const value = new coin.cosmos.base.v1beta1.Coin({
denom,
amount,
})
const refillBondMessage = new bondTx.vulcanize.bond.v1beta1.MsgRefillBond({
id,
signer,
coins: [value]
})
return {
message: refillBondMessage,
path: 'vulcanize.bond.v1beta1.MsgRefillBond',
}
}

View File

@ -1,8 +1,8 @@
import { createBond, sendDeposit, sendTokens, sendVote } from './index'
const SENDER_ADDRESS = 'ethm1ztkuzewqh0att04kn4gpkfk7vupmylcp3gr4zj';
const SENDER_PRIVATE_KEY = '765082238ae967c6e6514a7984410dfe268f233959a01c7dc746e8a5ac0faa9a';
const TO_ADDRESS = 'ethm1h3drdgazq4m4gtnxtl6kkuq3cxczrmnq6u24eq';
const SENDER_ADDRESS = 'ethm1kgwzff36qmx5tvfvfr7wvdurp5mr25csyqxgdm';
const SENDER_PRIVATE_KEY = '12e94bcc0daecd936b499f3eeb3b3b76ac1410cbaff2ee6c6f64d768453db0cf';
const TO_ADDRESS = 'ethm1e6r855un2ufnne9cdpujvan5srxjand37pepuz';
test('Send tokens', async () => {
await sendTokens(SENDER_PRIVATE_KEY, SENDER_ADDRESS, TO_ADDRESS)
@ -29,7 +29,7 @@ describe('Gov module', () => {
})
})
xdescribe('Bond module', () => {
describe('Bond module', () => {
test('Create bond', async () => {
const bondParams = {
amount: '100',

View File

@ -12,7 +12,7 @@ import {
} from '@tharsis/transactions'
import { createTxMsgDeposit, MessageMsgDeposit } from "./gov";
import { createTxMsgCreateBond, MessageMsgCreateBond } from "./bond";
import { createTxMsgCreateBond, createTxMsgRefillBond, MessageMsgCreateBond, MessageMsgRefillBond } from "./bond";
const ETHERMINT_REST_ENDPOINT = 'http://127.0.0.1:1317'
@ -140,6 +140,33 @@ export const createBond = async (senderPrivateKey: string, senderAddress: string
await signAndSendMessage(senderPrivateKey, chain, sender, msg)
}
export const refillBond = async (senderPrivateKey: string, senderAddress: string, params: MessageMsgRefillBond) => {
let { data: addrData} = await axios.get(`${ETHERMINT_REST_ENDPOINT}${generateEndpointAccount(senderAddress)}`)
const chain = {
chainId: 9000,
cosmosChainId: 'ethermint_9000-1',
}
const sender = {
accountAddress: addrData.account.base_account.address,
sequence: addrData.account.base_account.sequence,
accountNumber: addrData.account.base_account.account_number,
pubkey: addrData.account.base_account.pub_key.key,
}
const fee = {
amount: '20',
denom: 'aphoton',
gas: '200000',
}
const memo = ''
const msg = createTxMsgRefillBond(chain, sender, fee, memo, params)
await signAndSendMessage(senderPrivateKey, chain, sender, msg)
}
const signAndSendMessage = async (senderPrivateKey: string, chain: Chain, sender: Sender, msg: any) => {
const eipMessageDomain: any = msg.eipToSign.domain;