Expose credit tx to cli and test
This commit is contained in:
parent
3027eeb3c3
commit
9640547c01
|
@ -65,6 +65,7 @@ func main() {
|
|||
txcmd.RootCmd.AddCommand(
|
||||
// This is the default transaction, optional in your app
|
||||
coincmd.SendTxCmd,
|
||||
coincmd.CreditTxCmd,
|
||||
// this enables creating roles
|
||||
rolecmd.CreateRoleTxCmd,
|
||||
// these are for handling ibc
|
||||
|
|
|
@ -122,7 +122,7 @@ func GetGenesisJSON(chainID, addr string) string {
|
|||
]
|
||||
}],
|
||||
"plugin_options": [
|
||||
"coin/issuer", {"app": "sigs", "address": "%s"}
|
||||
"coin/issuer", {"app": "sigs", "addr": "%s"}
|
||||
]
|
||||
}
|
||||
}`, chainID, addr, addr)
|
||||
|
|
|
@ -17,6 +17,13 @@ var SendTxCmd = &cobra.Command{
|
|||
RunE: commands.RequireInit(sendTxCmd),
|
||||
}
|
||||
|
||||
// CreditTxCmd is CLI command to issue credit to one account
|
||||
var CreditTxCmd = &cobra.Command{
|
||||
Use: "credit",
|
||||
Short: "issue credit to one account",
|
||||
RunE: commands.RequireInit(creditTxCmd),
|
||||
}
|
||||
|
||||
//nolint
|
||||
const (
|
||||
FlagTo = "to"
|
||||
|
@ -29,9 +36,12 @@ func init() {
|
|||
flags.String(FlagTo, "", "Destination address for the bits")
|
||||
flags.String(FlagAmount, "", "Coins to send in the format <amt><coin>,<amt><coin>...")
|
||||
flags.String(FlagFrom, "", "Address sending coins, if not first signer")
|
||||
|
||||
fs2 := CreditTxCmd.Flags()
|
||||
fs2.String(FlagTo, "", "Destination address for the bits")
|
||||
fs2.String(FlagAmount, "", "Coins to send in the format <amt><coin>,<amt><coin>...")
|
||||
}
|
||||
|
||||
// sendTxCmd is an example of how to make a tx
|
||||
func sendTxCmd(cmd *cobra.Command, args []string) error {
|
||||
tx, err := readSendTxFlags()
|
||||
if err != nil {
|
||||
|
@ -62,6 +72,30 @@ func readSendTxFlags() (tx basecoin.Tx, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func creditTxCmd(cmd *cobra.Command, args []string) error {
|
||||
tx, err := readCreditTxFlags()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return txcmd.DoTx(tx)
|
||||
}
|
||||
|
||||
func readCreditTxFlags() (tx basecoin.Tx, err error) {
|
||||
// parse to address
|
||||
toAddr, err := commands.ParseActor(viper.GetString(FlagTo))
|
||||
if err != nil {
|
||||
return tx, err
|
||||
}
|
||||
|
||||
amount, err := coin.ParseCoins(viper.GetString(FlagAmount))
|
||||
if err != nil {
|
||||
return tx, err
|
||||
}
|
||||
|
||||
tx = coin.CreditTx{Debitor: toAddr, Credit: amount}.Wrap()
|
||||
return
|
||||
}
|
||||
|
||||
func readFromAddr() (basecoin.Actor, error) {
|
||||
from := viper.GetString(FlagFrom)
|
||||
if from == "" {
|
||||
|
|
|
@ -7,13 +7,17 @@ import (
|
|||
)
|
||||
|
||||
func init() {
|
||||
basecoin.TxMapper.RegisterImplementation(SendTx{}, TypeSend, ByteSend)
|
||||
basecoin.TxMapper.
|
||||
RegisterImplementation(SendTx{}, TypeSend, ByteSend).
|
||||
RegisterImplementation(CreditTx{}, TypeCredit, ByteCredit)
|
||||
}
|
||||
|
||||
// we reserve the 0x20-0x3f range for standard modules
|
||||
const (
|
||||
ByteSend = 0x20
|
||||
TypeSend = NameCoin + "/send"
|
||||
ByteSend = 0x20
|
||||
TypeSend = NameCoin + "/send"
|
||||
ByteCredit = 0x21
|
||||
TypeCredit = NameCoin + "/credit"
|
||||
)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
|
||||
// nolint
|
||||
const (
|
||||
ByteFees = 0x21
|
||||
ByteFees = 0x28
|
||||
TypeFees = NameFee + "/tx"
|
||||
)
|
||||
|
||||
|
|
|
@ -83,6 +83,23 @@ test02SendTxWithFee() {
|
|||
}
|
||||
|
||||
|
||||
test03CreditTx() {
|
||||
SENDER=$(getAddr $RICH)
|
||||
RECV=$(getAddr $POOR)
|
||||
|
||||
# make sure we are controlled by permissions (only rich can issue credit)
|
||||
assertFalse "line=${LINENO}, bad password" "echo qwertyuiop | ${CLIENT_EXE} tx credit --amount=1000mycoin --sequence=1 --to=$RECV --name=$POOR"
|
||||
TX=$(echo qwertyuiop | ${CLIENT_EXE} tx credit --amount=1000mycoin --sequence=3 --to=$RECV --name=$RICH)
|
||||
txSucceeded $? "$TX" "$RECV"
|
||||
HASH=$(echo $TX | jq .hash | tr -d \")
|
||||
TX_HEIGHT=$(echo $TX | jq .height)
|
||||
|
||||
# receiver got cash, sender didn't lose any (1000 more than last check)
|
||||
checkAccount $RECV "2082"
|
||||
checkAccount $SENDER "9007199254739900"
|
||||
}
|
||||
|
||||
|
||||
# Load common then run these tests with shunit2!
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" #get this files directory
|
||||
. $DIR/common.sh
|
||||
|
|
Loading…
Reference in New Issue