MCPcopy Create free account
hub / github.com/33cn/chain33 / TestPlugin

Function TestPlugin

executor/plugin_test.go:12–49  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func TestPlugin(t *testing.T) {
13 exec, _ := initEnv(types.GetDefaultCfgstring())
14 cfg := exec.client.GetConfig()
15 dir, ldb, kvdb := util.CreateTestDB()
16 defer util.CloseTestDB(dir, ldb)
17 ctx := &executorCtx{
18 stateHash: nil,
19 height: 1,
20 blocktime: time.Now().Unix(),
21 difficulty: 1,
22 mainHash: nil,
23 parentHash: nil,
24 }
25 var txs []*types.Transaction
26 addr, priv := util.Genaddress()
27 tx := util.CreateCoinsTx(cfg, priv, addr, types.DefaultCoinPrecision)
28 tx.Sign(types.SECP256K1, priv)
29 txs = append(txs, tx)
30 var stateHash [32]byte
31 stateHash[0] = 30
32 for _, plugin := range globalPlugins {
33 detail := &types.BlockDetail{
34 Block: &types.Block{Txs: txs, StateHash: stateHash[:]},
35 Receipts: []*types.ReceiptData{{}},
36 }
37 executor := newExecutor(ctx, exec, kvdb, txs, nil)
38 _, _, err := plugin.CheckEnable(executor, false)
39 assert.NoError(t, err)
40 kvs, err := plugin.ExecLocal(executor, detail)
41 assert.NoError(t, err)
42 for _, kv := range kvs {
43 err = kvdb.Set(kv.Key, kv.Value)
44 assert.NoError(t, err)
45 }
46 _, err = plugin.ExecDelLocal(executor, detail)
47 assert.NoError(t, err)
48 }
49}
50
51func TestPluginBase(t *testing.T) {
52 exec, _ := initEnv(types.GetDefaultCfgstring())

Callers

nothing calls this directly

Calls 13

GetDefaultCfgstringFunction · 0.92
CreateTestDBFunction · 0.92
CloseTestDBFunction · 0.92
GenaddressFunction · 0.92
CreateCoinsTxFunction · 0.92
newExecutorFunction · 0.85
initEnvFunction · 0.70
GetConfigMethod · 0.65
SignMethod · 0.65
CheckEnableMethod · 0.65
ExecLocalMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected