github.com/turingchain2020/turingchain@v1.1.21/types/types_real_test.go (about) 1 // Copyright Turing Corp. 2018 All Rights Reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package types_test 6 7 import ( 8 "testing" 9 10 "strings" 11 12 "github.com/turingchain2020/turingchain/common/address" 13 _ "github.com/turingchain2020/turingchain/system" 14 "github.com/turingchain2020/turingchain/types" 15 "github.com/stretchr/testify/assert" 16 ) 17 18 //how to create transafer for para 19 func TestCallCreateTxPara(t *testing.T) { 20 str := types.ReadFile("testdata/guodun2.toml") 21 new := strings.Replace(str, "Title=\"user.p.guodun2.\"", "Title=\"user.p.sto.\"", 1) 22 cfg := types.NewTuringchainConfig(new) 23 24 req := &types.CreateTx{ 25 To: "184wj4nsgVxKyz2NhM3Yb5RK5Ap6AFRFq2", 26 Amount: 10, 27 Fee: 1, 28 Note: []byte("12312"), 29 IsWithdraw: false, 30 IsToken: false, 31 TokenSymbol: "", 32 ExecName: cfg.ExecName("coins"), 33 } 34 assert.True(t, cfg.IsPara()) 35 tx, err := types.CallCreateTransaction("coins", "", req) 36 assert.Nil(t, err) 37 tx, err = types.FormatTx(cfg, "coins", tx) 38 assert.Nil(t, err) 39 assert.Equal(t, "coins", string(tx.Execer)) 40 assert.Equal(t, address.ExecAddress("coins"), tx.To) 41 tx, err = types.FormatTx(cfg, cfg.ExecName("coins"), tx) 42 assert.Nil(t, err) 43 assert.Equal(t, "user.p.sto.coins", string(tx.Execer)) 44 assert.Equal(t, address.ExecAddress("user.p.sto.coins"), tx.To) 45 } 46 47 func TestExecName(t *testing.T) { 48 cfg := types.NewTuringchainConfig(types.GetDefaultCfgstring()) 49 assert.Equal(t, cfg.ExecName("coins"), "coins") 50 cfg.SetTitleOnlyForTest("user.p.sto.") 51 assert.Equal(t, cfg.ExecName("coins"), "user.p.sto.coins") 52 //#在exec前面加一个 # 表示不重写执行器 53 assert.Equal(t, cfg.ExecName("#coins"), "coins") 54 }