func TestMsgSetWithdrawAddressRoute(t *testing.T) {
	msg := NewMsgSetWithdrawAddress(testOwner, testWithdrawAddr)
	require.Equal(t, RouterKey, msg.Route())
}
TestMsgSetWithdrawAddressRoute tests Route for MsgSetWithdrawAddress
package types
import (
	"fmt"
	"strings"
	"testing"
	"github.com/stretchr/testify/require"
	"github.com/tendermint/tendermint/crypto/tmhash"
	sdk "github.com/cosmos/cosmos-sdk/types"
)
var (
	emptyAddress = ""
	testCoin1 = sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(10000))
	testCoin2 = sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100))
	testServiceName = "test-service"
	testServiceDesc = "test-service-desc"
	testServiceTags = []string{"tag1", "tag2"}
	testAuthor      = sdk.AccAddress(tmhash.SumTruncated([]byte("test-author"))).String()
	testAuthorDesc  = "test-author-desc"
	testSchemas     = `{"input":{"type":"object"},"output":{"type":"object"}}`
	testOwner        = sdk.AccAddress(tmhash.SumTruncated([]byte("test-owner"))).String()
	testProvider     = sdk.AccAddress(tmhash.SumTruncated([]byte("test-provider"))).String()
	testDeposit      = sdk.NewCoins(testCoin1)
	testPricing      = `{"price":"1stake"}`
	testQoS          = uint64(50)
	testOptions      = "{}"
	testWithdrawAddr = sdk.AccAddress(tmhash.SumTruncated([]byte("test-withdrawal-address"))).String()
	testAddedDeposit = sdk.NewCoins(testCoin2)
	testConsumer      = sdk.AccAddress(tmhash.SumTruncated([]byte("test-consumer"))).String()
	testProviders     = []string{testProvider}
	testInput         = `{"header":{},"body":{"pair":"iris-usdt"}}`
	testServiceFeeCap = sdk.NewCoins(testCoin2)
	testTimeout       = int64(100)
	testRepeatedFreq  = uint64(120)
	testRepeatedTotal = int64(100)
	testResult = `{"code":200,"message":""}`
	testOutput = `{"header":{},"body":{"last":"100"}}`
	rawTestRequestContextID = GenerateRequestContextID(tmhash.Sum([]byte("test-request-context-id")), 0)
	testRequestContextID    = rawTestRequestContextID.String()
	testRequestID           = GenerateRequestID(rawTestRequestContextID, 1, 1, 1).String()
	invalidName = "invalid/service/name"
)
func TestMsgDefineServiceRoute(t *testing.T) {
	msg := NewMsgDefineService(testServiceName, testServiceDesc, testServiceTags, testAuthor, testAuthorDesc, testSchemas)
	require.Equal(t, RouterKey, msg.Route())
}
func TestMsgDefineServiceType(t *testing.T) {
	msg := NewMsgDefineService(testServiceName, testServiceDesc, testServiceTags, testAuthor, testAuthorDesc, testSchemas)
	require.Equal(t, "define_service", msg.Type())
}
func TestMsgDefineServiceValidation(t *testing.T) {
	invalidLongName := strings.Repeat("s", MaxNameLength+1)
	invalidLongDesc := strings.Repeat("d", MaxDescriptionLength+1)
	invalidMoreTags := strings.Split("t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11", ",")
	invalidLongTags := []string{strings.Repeat("t", MaxTagLength+1)}
	invalidEmptyTags := []string{"t1", ""}
	invalidDuplicateTags := []string{"t1", "t1"}
	invalidSchemas := `{"input":"nonobject","output":"nonobject"}`
	invalidSchemasNoInput := `{"output":{"type":"object"}}`
	invalidSchemasNoOutput := `{"input":{"type":"object"}}`
	testMsgs := []*MsgDefineService{
		NewMsgDefineService(testServiceName, testServiceDesc, testServiceTags, testAuthor, testAuthorDesc, testSchemas),             
		NewMsgDefineService(testServiceName, testServiceDesc, testServiceTags, emptyAddress, testAuthorDesc, testSchemas),           
		NewMsgDefineService(invalidName, testServiceDesc, testServiceTags, testAuthor, testAuthorDesc, testSchemas),                 
		NewMsgDefineService(invalidLongName, testServiceDesc, testServiceTags, testAuthor, testAuthorDesc, testSchemas),             
		NewMsgDefineService(testServiceName, invalidLongDesc, testServiceTags, testAuthor, testAuthorDesc, testSchemas),             
		NewMsgDefineService(testServiceName, testServiceDesc, invalidMoreTags, testAuthor, testAuthorDesc, testSchemas),             
		NewMsgDefineService(testServiceName, testServiceDesc, invalidLongTags, testAuthor, testAuthorDesc, testSchemas),             
		NewMsgDefineService(testServiceName, testServiceDesc, invalidEmptyTags, testAuthor, testAuthorDesc, testSchemas),            
		NewMsgDefineService(testServiceName, testServiceDesc, invalidDuplicateTags, testAuthor, testAuthorDesc, testSchemas),        
		NewMsgDefineService(testServiceName, testServiceDesc, testServiceTags, testAuthor, invalidLongDesc, testSchemas),            
		NewMsgDefineService(testServiceName, testServiceDesc, testServiceTags, testAuthor, testAuthorDesc, invalidSchemas),          
		NewMsgDefineService(testServiceName, testServiceDesc, testServiceTags, testAuthor, testAuthorDesc, invalidSchemasNoInput),   
		NewMsgDefineService(testServiceName, testServiceDesc, testServiceTags, testAuthor, testAuthorDesc, invalidSchemasNoOutput),  
	}
	testCases := []struct {
		msg     *MsgDefineService
		expPass bool
		errMsg  string
	}{
		{testMsgs[0], true, ""},
		{testMsgs[1], false, "missing author address"},
		{testMsgs[2], false, "service name contains illegal characters"},
		{testMsgs[3], false, "too long service name"},
		{testMsgs[4], false, "too long service description"},
		{testMsgs[5], false, "too many tags"},
		{testMsgs[6], false, "too long tag"},
		{testMsgs[7], false, "empty tag"},
		{testMsgs[8], false, "duplicate tags"},
		{testMsgs[9], false, "too long author description"},
		{testMsgs[10], false, "invalid schemas"},
		{testMsgs[11], false, "missing input schema"},
		{testMsgs[12], false, "missing output schema"},
	}
	for i, tc := range testCases {
		err := tc.msg.ValidateBasic()
		if tc.expPass {
			require.NoError(t, err, "Msg %d failed: %v", i, err)
		} else {
			require.Error(t, err, "Invalid Msg %d passed: %s", i, tc.errMsg)
		}
	}
}
func TestMsgDefineServiceGetSignBytes(t *testing.T) {
	msg := NewMsgDefineService(testServiceName, testServiceDesc, testServiceTags, testAuthor, testAuthorDesc, testSchemas)
	res := msg.GetSignBytes()
	expected := `{"type":"irismod/service/MsgDefineService","value":{"author":"cosmos1tkelht5u9ywfaww3fehvdtvncwwhf539w406rh","author_description":"test-author-desc","description":"test-service-desc","name":"test-service","schemas":"{\"input\":{\"type\":\"object\"},\"output\":{\"type\":\"object\"}}","tags":["tag1","tag2"]}}`
	require.Equal(t, expected, string(res))
}
func TestMsgDefineServiceGetSigners(t *testing.T) {
	msg := NewMsgDefineService(testServiceName, testServiceDesc, testServiceTags, testAuthor, testAuthorDesc, testSchemas)
	res := msg.GetSigners()
	expected := "[5DB3FBAE9C291C9EB9D14E6EC6AD93C39D74D225]"
	require.Equal(t, expected, fmt.Sprintf("%v", res))
}
func TestMsgBindServiceRoute(t *testing.T) {
	msg := NewMsgBindService(testServiceName, testProvider, testDeposit, testPricing, testQoS, testOptions, testOwner)
	require.Equal(t, RouterKey, msg.Route())
}
func TestMsgBindServiceType(t *testing.T) {
	msg := NewMsgBindService(testServiceName, testProvider, testDeposit, testPricing, testQoS, testOptions, testOwner)
	require.Equal(t, "bind_service", msg.Type())
}
func TestMsgBindServiceValidation(t *testing.T) {
	invalidLongName := strings.Repeat("s", MaxNameLength+1)
	invalidDeposit := sdk.Coins{sdk.Coin{Denom: "stake", Amount: sdk.NewInt(-1)}}
	invalidQoS := uint64(0)
	invalidPricing := `{"price":"1stake","other":"notallowedfield"}`
	invalidDenomPricing := `{"price":"5invalid#denom"}`
	invalidPromotionTimePricing := `{"price":"1stake","promotions_by_time":[{"start_time":"2018-10-10T13:30:30","end_time":"2019-10-10T13:30:30Z","discount":"0.8"}]}`
	invalidPromotionVolPricing := `{"price":"1stake","promotions_by_volume":[{"volume":0,"discount":"0.7"}]}`
	invalidOptions := ""
	validUpperDenomPricing := `{"price":"5ibc/9EBF7EBE6F8FFD34617809F3CF00E04A10D8B7226048F68866371FB9DAD8A25D"}`
	testMsgs := []*MsgBindService{
		NewMsgBindService(testServiceName, testProvider, testDeposit, testPricing, testQoS, testOptions, testOwner),                  
		NewMsgBindService(testServiceName, testProvider, testDeposit, validUpperDenomPricing, testQoS, testOptions, testOwner),       
		NewMsgBindService(testServiceName, emptyAddress, testDeposit, testPricing, testQoS, testOptions, testOwner),                  
		NewMsgBindService(testServiceName, testProvider, testDeposit, testPricing, testQoS, testOptions, emptyAddress),               
		NewMsgBindService(invalidName, testProvider, testDeposit, testPricing, testQoS, testOptions, testOwner),                      
		NewMsgBindService(invalidLongName, testProvider, testDeposit, testPricing, testQoS, testOptions, testOwner),                  
		NewMsgBindService(testServiceName, testProvider, invalidDeposit, testPricing, testQoS, testOptions, testOwner),               
		NewMsgBindService(testServiceName, testProvider, testDeposit, "", testQoS, testOptions, testOwner),                           
		NewMsgBindService(testServiceName, testProvider, testDeposit, invalidPricing, testQoS, testOptions, testOwner),               
		NewMsgBindService(testServiceName, testProvider, testDeposit, invalidDenomPricing, testQoS, testOptions, testOwner),          
		NewMsgBindService(testServiceName, testProvider, testDeposit, invalidPromotionTimePricing, testQoS, testOptions, testOwner),  
		NewMsgBindService(testServiceName, testProvider, testDeposit, invalidPromotionVolPricing, testQoS, testOptions, testOwner),   
		NewMsgBindService(testServiceName, testProvider, testDeposit, testPricing, invalidQoS, testOptions, testOwner),               
		NewMsgBindService(testServiceName, testProvider, testDeposit, testPricing, testQoS, invalidOptions, testOwner),               
	}
	testCases := []struct {
		msg     *MsgBindService
		expPass bool
		errMsg  string
	}{
		{testMsgs[0], true, ""},
		{testMsgs[1], true, ""},
		{testMsgs[2], false, "missing provider address"},
		{testMsgs[3], false, "missing owner address"},
		{testMsgs[4], false, "service name contains illegal characters"},
		{testMsgs[5], false, "too long service name"},
		{testMsgs[6], false, "invalid deposit"},
		{testMsgs[7], false, "missing pricing"},
		{testMsgs[8], false, "invalid Pricing JSON Schema instance"},
		{testMsgs[9], false, "invalid pricing denom"},
		{testMsgs[10], false, "invalid promotion time lack of time zone"},
		{testMsgs[11], false, "invalid promotion volume"},
		{testMsgs[12], false, "invalid qos"},
		{testMsgs[13], false, "invalid options"},
	}
	for i, tc := range testCases {
		err := tc.msg.ValidateBasic()
		if tc.expPass {
			require.NoError(t, err, "Msg %d failed: %v", i, err)
		} else {
			require.Error(t, err, "Invalid Msg %d passed: %s", i, tc.errMsg)
		}
	}
}
func TestMsgBindServiceGetSignBytes(t *testing.T) {
	msg := NewMsgBindService(testServiceName, testProvider, testDeposit, testPricing, testQoS, testOptions, testOwner)
	res := msg.GetSignBytes()
	expected := `{"type":"irismod/service/MsgBindService","value":{"deposit":[{"amount":"10000","denom":"stake"}],"options":"{}","owner":"cosmos1dtrajkx72qwf8gesp2z4rjz6p7klycmmh2lnvn","pricing":"{\"price\":\"1stake\"}","provider":"cosmos10yajkmnug9d2nvccgs7ul3xkur0l9as348gmwe","qos":"50","service_name":"test-service"}}`
	require.Equal(t, expected, string(res))
}
func TestMsgBindServiceGetSigners(t *testing.T) {
	msg := NewMsgBindService(testServiceName, testProvider, testDeposit, testPricing, testQoS, "", testOwner)
	res := msg.GetSigners()
	require.Equal(t, "[6AC7D958DE501C93A3300A8551C85A0FADF2637B]", fmt.Sprintf("%v", res))
}
func TestMsgUpdateServiceBindingRoute(t *testing.T) {
	msg := NewMsgUpdateServiceBinding(testServiceName, testProvider, testAddedDeposit, "", 0, testOptions, testOwner)
	require.Equal(t, RouterKey, msg.Route())
}
func TestMsgUpdateServiceBindingType(t *testing.T) {
	msg := NewMsgUpdateServiceBinding(testServiceName, testProvider, testAddedDeposit, "", 0, testOptions, testOwner)
	require.Equal(t, "update_service_binding", msg.Type())
}
func TestMsgUpdateServiceBindingValidation(t *testing.T) {
	emptyAddedDeposit := sdk.Coins{}
	invalidLongName := strings.Repeat("s", MaxNameLength+1)
	invalidPricing := `{"price":"1stake","other":"notallowedfield"}`
	invalidDenomPricing := `{"price":"1invaliddenom*"}`
	invalidPromotionTimePricing := `{"price":"1stake","promotions_by_time":[{"start_time":"2018-10-10T13:30:30","end_time":"2019-10-10T13:30:30Z","discount":"0.8"}]}`
	invalidPromotionVolPricing := `{"price":"1stake","promotions_by_volume":[{"volume":0,"discount":"0.7"}]}`
	invalidOptions := ""
	validUpperDenomPricing := `{"price":"5ibc/9EBF7EBE6F8FFD34617809F3CF00E04A10D8B7226048F68866371FB9DAD8A25D"}`
	testMsgs := []*MsgUpdateServiceBinding{
		NewMsgUpdateServiceBinding(testServiceName, testProvider, testAddedDeposit, testPricing, testQoS, testOptions, testOwner),                    
		NewMsgUpdateServiceBinding(testServiceName, testProvider, testAddedDeposit, validUpperDenomPricing, testQoS, testOptions, testOwner),         
		NewMsgUpdateServiceBinding(testServiceName, testProvider, emptyAddedDeposit, testPricing, testQoS, testOptions, testOwner),                   
		NewMsgUpdateServiceBinding(testServiceName, testProvider, testAddedDeposit, "", testQoS, testOptions, testOwner),                             
		NewMsgUpdateServiceBinding(testServiceName, testProvider, testAddedDeposit, testPricing, 0, testOptions, testOwner),                          
		NewMsgUpdateServiceBinding(testServiceName, testProvider, emptyAddedDeposit, "", 0, testOptions, testOwner),                                  
		NewMsgUpdateServiceBinding(testServiceName, emptyAddress, testAddedDeposit, testPricing, testQoS, testOptions, testOwner),                    
		NewMsgUpdateServiceBinding(testServiceName, testProvider, testAddedDeposit, testPricing, testQoS, testOptions, emptyAddress),                 
		NewMsgUpdateServiceBinding(invalidName, testProvider, testAddedDeposit, testPricing, testQoS, testOptions, testOwner),                        
		NewMsgUpdateServiceBinding(invalidLongName, testProvider, testAddedDeposit, testPricing, testQoS, testOptions, testOwner),                    
		NewMsgUpdateServiceBinding(testServiceName, testProvider, testAddedDeposit, invalidPricing, testQoS, testOptions, testOwner),                 
		NewMsgUpdateServiceBinding(testServiceName, testProvider, testAddedDeposit, invalidDenomPricing, testQoS, testOptions, testOwner),            
		NewMsgUpdateServiceBinding(testServiceName, testProvider, testAddedDeposit, invalidPromotionTimePricing, testQoS, testOptions, testOwner),    
		NewMsgUpdateServiceBinding(testServiceName, testProvider, testAddedDeposit, invalidPromotionVolPricing, testQoS, testOptions, testOwner),     
		NewMsgUpdateServiceBinding(testServiceName, testProvider, testAddedDeposit, invalidPromotionVolPricing, testQoS, invalidOptions, testOwner),  
	}
	testCases := []struct {
		msg     *MsgUpdateServiceBinding
		expPass bool
		errMsg  string
	}{
		{testMsgs[0], true, ""},
		{testMsgs[1], true, ""},
		{testMsgs[2], true, ""},
		{testMsgs[3], true, ""},
		{testMsgs[4], true, ""},
		{testMsgs[5], true, ""},
		{testMsgs[6], false, "missing provider address"},
		{testMsgs[7], false, "missing owner address"},
		{testMsgs[8], false, "service name contains illegal characters"},
		{testMsgs[9], false, "too long service name"},
		{testMsgs[10], false, "invalid Pricing JSON Schema instance"},
		{testMsgs[11], false, "invalid pricing denom"},
		{testMsgs[12], false, "invalid promotion time lack of time zone"},
		{testMsgs[13], false, "invalid promotion volume"},
		{testMsgs[14], false, "invalid options"},
	}
	for i, tc := range testCases {
		err := tc.msg.ValidateBasic()
		if tc.expPass {
			require.NoError(t, err, "Msg %d failed: %v", i, err)
		} else {
			require.Error(t, err, "Invalid Msg %d passed: %s", i, tc.errMsg)
		}
	}
}
func TestMsgUpdateServiceBindingGetSignBytes(t *testing.T) {
	msg := NewMsgUpdateServiceBinding(testServiceName, testProvider, testAddedDeposit, "{\"price\":\"1\"}", 1, "", testOwner)
	res := msg.GetSignBytes()
	expected := `{"type":"irismod/service/MsgUpdateServiceBinding","value":{"deposit":[{"amount":"100","denom":"stake"}],"owner":"cosmos1dtrajkx72qwf8gesp2z4rjz6p7klycmmh2lnvn","pricing":"{\"price\":\"1\"}","provider":"cosmos10yajkmnug9d2nvccgs7ul3xkur0l9as348gmwe","qos":"1","service_name":"test-service"}}`
	require.Equal(t, expected, string(res))
}
func TestMsgUpdateServiceBindingGetSigners(t *testing.T) {
	msg := NewMsgUpdateServiceBinding(testServiceName, testProvider, testAddedDeposit, "", 0, testOptions, testOwner)
	res := msg.GetSigners()
	require.Equal(t, "[6AC7D958DE501C93A3300A8551C85A0FADF2637B]", fmt.Sprintf("%v", res))
}