Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
plugin
Commits
3f3dd047
Unverified
Commit
3f3dd047
authored
Mar 01, 2019
by
vipwzw
Committed by
GitHub
Mar 01, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #322 from linj-disanbo/js-creator
Js creator
parents
32187648
9e69cb9f
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
165 additions
and
1 deletion
+165
-1
case.go
plugin/dapp/js/autotest/case.go
+24
-0
js.go
plugin/dapp/js/autotest/js.go
+28
-0
js.toml
plugin/dapp/js/autotest/js.toml
+19
-0
creator.go
plugin/dapp/js/executor/creator.go
+41
-0
exec.go
plugin/dapp/js/executor/exec.go
+6
-1
jsvm_test.go
plugin/dapp/js/executor/jsvm_test.go
+11
-0
rpc_test.go
plugin/dapp/js/executor/rpc_test.go
+28
-0
plugin.go
plugin/dapp/js/plugin.go
+3
-0
js.go
plugin/dapp/js/types/js.go
+5
-0
No files found.
plugin/dapp/js/autotest/case.go
0 → 100644
View file @
3f3dd047
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
autotest
import
(
"github.com/33cn/chain33/cmd/autotest/types"
)
// JsCreateCase token createcase command
type
JsCreateCase
struct
{
types
.
BaseCase
}
// JsCreatePack defines create package command
type
JsCreatePack
struct
{
types
.
BaseCasePack
}
// SendCommand defines send command function of tokenprecreatecase
func
(
testCase
*
JsCreateCase
)
SendCommand
(
packID
string
)
(
types
.
PackFunc
,
error
)
{
return
types
.
DefaultSend
(
testCase
,
&
JsCreatePack
{},
packID
)
}
plugin/dapp/js/autotest/js.go
0 → 100644
View file @
3f3dd047
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
autotest
import
(
"reflect"
"github.com/33cn/chain33/cmd/autotest/types"
)
type
jsAutoTest
struct
{
SimpleCaseArr
[]
types
.
SimpleCase
`toml:"SimpleCase,omitempty"`
JSCreateCaseArr
[]
JsCreateCase
`toml:"jsCreateCase,omitempty"`
}
func
init
()
{
types
.
RegisterAutoTest
(
jsAutoTest
{})
}
func
(
config
jsAutoTest
)
GetName
()
string
{
return
"js"
}
func
(
config
jsAutoTest
)
GetTestConfigType
()
reflect
.
Type
{
return
reflect
.
TypeOf
(
config
)
}
plugin/dapp/js/autotest/js.toml
0 → 100644
View file @
3f3dd047
# 1Q8hGLfoGe63efeWa8fJ4Pnukhkngt6poK manage addr
# 0xc34b5d9d44ac7b754806f761d3d4d2c4fe5214f6b074c19f069c4f5c2a29c8cc
[[jsCreateCase]]
id
=
"create1"
command
=
"send jsvm create -c ../../../plugin/dapp/js/executor/game.js -n hello -k 14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
fail
=
true
[[jsCreateCase]]
id
=
"create2"
command
=
"send jsvm create -c ../../../plugin/dapp/js/executor/game.js -n hello -k 14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
dep
=
[
"create1"
,
"configJS"
]
[[SimpleCase]]
id
=
"configJS"
dep
=
["create1"]
command
=
"send config config_tx -c js-creator -o add -v 14KEKbYtKKQm4wMthSK9J4La4nAiidGozt -k 0xc34b5d9d44ac7b754806f761d3d4d2c4fe5214f6b074c19f069c4f5c2a29c8cc"
\ No newline at end of file
plugin/dapp/js/executor/creator.go
0 → 100644
View file @
3f3dd047
// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package
executor
import
(
dbm
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/types"
ptypes
"github.com/33cn/plugin/plugin/dapp/js/types"
)
func
getManageKey
(
key
string
,
db
dbm
.
KV
)
([]
byte
,
error
)
{
manageKey
:=
types
.
ManageKey
(
key
)
return
db
.
Get
([]
byte
(
manageKey
))
}
func
checkPriv
(
addr
,
key
string
,
db
dbm
.
KV
)
error
{
value
,
err
:=
getManageKey
(
key
,
db
)
if
err
!=
nil
{
return
err
}
if
value
==
nil
{
return
ptypes
.
ErrJsCreator
}
var
item
types
.
ConfigItem
err
=
types
.
Decode
(
value
,
&
item
)
if
err
!=
nil
{
return
err
}
for
_
,
op
:=
range
item
.
GetArr
()
.
Value
{
if
op
==
addr
{
return
nil
}
}
return
ptypes
.
ErrJsCreator
}
plugin/dapp/js/executor/exec.go
View file @
3f3dd047
...
...
@@ -8,13 +8,18 @@ import (
)
func
(
c
*
js
)
Exec_Create
(
payload
*
jsproto
.
Create
,
tx
*
types
.
Transaction
,
index
int
)
(
*
types
.
Receipt
,
error
)
{
err
:=
checkPriv
(
tx
.
From
(),
ptypes
.
JsCreator
,
c
.
GetStateDB
())
if
err
!=
nil
{
return
nil
,
err
}
execer
:=
types
.
ExecName
(
"user."
+
ptypes
.
JsX
+
"."
+
payload
.
Name
)
if
string
(
tx
.
Execer
)
!=
ptypes
.
JsX
{
return
nil
,
types
.
ErrExecNameNotMatch
}
c
.
prefix
=
calcStatePrefix
([]
byte
(
execer
))
kvc
:=
dapp
.
NewKVCreator
(
c
.
GetStateDB
(),
c
.
prefix
,
nil
)
_
,
err
:
=
kvc
.
GetNoPrefix
(
calcCodeKey
(
payload
.
Name
))
_
,
err
=
kvc
.
GetNoPrefix
(
calcCodeKey
(
payload
.
Name
))
if
err
!=
nil
&&
err
!=
types
.
ErrNotFound
{
return
nil
,
err
}
...
...
plugin/dapp/js/executor/jsvm_test.go
View file @
3f3dd047
...
...
@@ -37,6 +37,17 @@ func initExec(ldb db.DB, kvdb db.KVDB, code string, t assert.TestingT) *js {
e
.
SetLocalDB
(
kvdb
)
e
.
SetStateDB
(
kvdb
)
c
,
tx
:=
createCodeTx
(
"test"
,
code
)
// set config key
item
:=
&
types
.
ConfigItem
{
Key
:
"mavl-manage-js-creator"
,
Addr
:
tx
.
From
(),
Value
:
&
types
.
ConfigItem_Arr
{
Arr
:
&
types
.
ArrayConfig
{
Value
:
[]
string
{
tx
.
From
()}},
},
}
kvdb
.
Set
([]
byte
(
item
.
Key
),
types
.
Encode
(
item
))
receipt
,
err
:=
e
.
Exec_Create
(
c
,
tx
,
0
)
assert
.
Nil
(
t
,
err
)
util
.
SaveKVList
(
ldb
,
receipt
.
KV
)
...
...
plugin/dapp/js/executor/rpc_test.go
View file @
3f3dd047
...
...
@@ -30,6 +30,8 @@ func TestJsVM(t *testing.T) {
mocker
:=
testnode
.
NewWithConfig
(
cfg
,
sub
,
nil
)
defer
mocker
.
Close
()
mocker
.
Listen
()
configCreator
(
mocker
,
t
)
//开始部署合约, 测试阶段任何人都可以部署合约
//后期需要加上权限控制
//1. 部署合约
...
...
@@ -94,6 +96,9 @@ func TestJsGame(t *testing.T) {
mocker
.
Listen
()
err
:=
mocker
.
SendHot
()
assert
.
Nil
(
t
,
err
)
// 需要配置
configCreator
(
mocker
,
t
)
//开始部署合约, 测试阶段任何人都可以部署合约
//后期需要加上权限控制
//1. 部署合约
...
...
@@ -288,3 +293,26 @@ func TestJsGame(t *testing.T) {
assert
.
Nil
(
t
,
err
)
t
.
Log
(
queryresult
.
Data
)
}
func
configCreator
(
mocker
*
testnode
.
Chain33Mock
,
t
*
testing
.
T
)
{
// 需要配置
addr
:=
address
.
PubKeyToAddress
(
mocker
.
GetHotKey
()
.
PubKey
()
.
Bytes
())
.
String
()
creator
:=
&
types
.
ModifyConfig
{
Key
:
"js-creator"
,
Op
:
"add"
,
Value
:
addr
,
Addr
:
addr
,
}
cfgReq
:=
&
rpctypes
.
CreateTxIn
{
Execer
:
"manage"
,
ActionName
:
"Modify"
,
Payload
:
types
.
MustPBToJSON
(
creator
),
}
var
cfgtxhex
string
err
:=
mocker
.
GetJSONC
()
.
Call
(
"Chain33.CreateTransaction"
,
cfgReq
,
&
cfgtxhex
)
assert
.
Nil
(
t
,
err
)
hash1
,
err
:=
mocker
.
SendAndSign
(
mocker
.
GetHotKey
(),
cfgtxhex
)
assert
.
Nil
(
t
,
err
)
_
,
err
=
mocker
.
WaitTx
(
hash1
)
assert
.
Nil
(
t
,
err
)
}
plugin/dapp/js/plugin.go
View file @
3f3dd047
...
...
@@ -5,6 +5,9 @@ import (
"github.com/33cn/plugin/plugin/dapp/js/cmd"
"github.com/33cn/plugin/plugin/dapp/js/executor"
ptypes
"github.com/33cn/plugin/plugin/dapp/js/types"
// init auto test
_
"github.com/33cn/plugin/plugin/dapp/js/autotest"
)
func
init
()
{
...
...
plugin/dapp/js/types/js.go
View file @
3f3dd047
...
...
@@ -19,6 +19,9 @@ const (
TyLogJs
=
10000
)
// JsCreator 配置项 创建js合约的管理员
const
JsCreator
=
"js-creator"
var
(
typeMap
=
map
[
string
]
int32
{
"Create"
:
jsActionCreate
,
...
...
@@ -47,6 +50,8 @@ var (
ErrSymbolName
=
errors
.
New
(
"chain33.js: ErrSymbolName"
)
ErrExecerName
=
errors
.
New
(
"chain33.js: ErrExecerName"
)
ErrDBType
=
errors
.
New
(
"chain33.js: ErrDBType"
)
// ErrJsCreator
ErrJsCreator
=
errors
.
New
(
"ErrJsCreator"
)
)
func
init
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment