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
bfe53eff
Commit
bfe53eff
authored
Nov 29, 2018
by
Litian
Committed by
33cn
Nov 29, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add ut
parent
1448f0ef
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
111 additions
and
0 deletions
+111
-0
evm.go
plugin/dapp/evm/types/evm.go
+6
-0
evm_test.go
plugin/dapp/evm/types/evm_test.go
+105
-0
No files found.
plugin/dapp/evm/types/evm.go
View file @
bfe53eff
...
...
@@ -13,6 +13,7 @@ import (
log
"github.com/33cn/chain33/common/log/log15"
"github.com/33cn/chain33/types"
"github.com/golang/protobuf/proto"
"errors"
)
var
(
...
...
@@ -139,6 +140,11 @@ func createEvmTx(param *CreateCallTx) (*types.Transaction, error) {
}
if
param
.
IsCreate
{
if
len
(
action
.
Abi
)
>
0
&&
len
(
action
.
Code
)
==
0
{
elog
.
Error
(
"create evm Tx error, code is empty"
)
return
nil
,
errors
.
New
(
"code must be set in create tx"
)
}
return
createRawTx
(
action
,
""
,
param
.
Fee
)
}
return
createRawTx
(
action
,
param
.
Name
,
param
.
Fee
)
...
...
plugin/dapp/evm/types/evm_test.go
0 → 100644
View file @
bfe53eff
package
types
import
(
"encoding/hex"
"encoding/json"
"github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/types"
"github.com/stretchr/testify/assert"
"testing"
)
// TestEvmType_CreateTx 测试RPC创建交易逻辑
func
TestEvmType_CreateTx
(
t
*
testing
.
T
)
{
evm
:=
&
EvmType
{}
errMap
:=
map
[
int
]
string
{
2
:
"code must be set in create tx"
,
4
:
"encoding/hex: invalid byte: U+0078 'x'"
}
for
idx
,
test
:=
range
[]
CreateCallTx
{
{
Code
:
"abddee"
,
Abi
:
"[{}]"
,
IsCreate
:
true
,
Name
:
"user.evm.xxx"
,
Note
:
"test"
,
Alias
:
"mycon"
,
Fee
:
5000000
,
Amount
:
100000000
,
},
{
Code
:
"abddee"
,
Abi
:
""
,
IsCreate
:
true
,
Name
:
"user.evm.xxx"
,
Note
:
"test"
,
Alias
:
"mycon"
,
Fee
:
5000000
,
Amount
:
100000000
,
},
{
Code
:
""
,
Abi
:
"[{}]"
,
IsCreate
:
true
,
Name
:
"user.evm.xxx"
,
Note
:
"test"
,
Alias
:
"mycon"
,
Fee
:
5000000
,
Amount
:
100000000
,
},
{
Code
:
"abccdd"
,
Abi
:
"[{}]"
,
IsCreate
:
false
,
Name
:
"user.evm.xxx"
,
Note
:
"test"
,
Alias
:
"mycon"
,
Fee
:
0
,
Amount
:
100000000
,
},
{
Code
:
"xyz"
,
Abi
:
"[{}]"
,
IsCreate
:
true
,
Name
:
"user.evm.xxx"
,
Note
:
"test"
,
Alias
:
"mycon"
,
Fee
:
5000000
,
Amount
:
100000000
,
},
}
{
data
,
err
:=
json
.
Marshal
(
&
test
)
assert
.
NoError
(
t
,
err
)
tx
,
err
:=
evm
.
CreateTx
(
"CreateCall"
,
data
)
if
er
,
ok
:=
errMap
[
idx
];
ok
{
assert
.
EqualError
(
t
,
err
,
er
)
continue
}
else
{
assert
.
NoError
(
t
,
err
)
}
var
action
EVMContractAction
types
.
Decode
(
tx
.
Payload
,
&
action
)
assert
.
EqualValues
(
t
,
test
.
Amount
,
action
.
Amount
)
assert
.
EqualValues
(
t
,
test
.
Abi
,
action
.
Abi
)
assert
.
EqualValues
(
t
,
test
.
Alias
,
action
.
Alias
)
assert
.
EqualValues
(
t
,
test
.
Note
,
action
.
Note
)
if
tx
.
Fee
<
test
.
Fee
{
assert
.
Fail
(
t
,
"tx fee low"
)
}
if
len
(
test
.
Code
)
>
0
{
bcode
,
err
:=
hex
.
DecodeString
(
test
.
Code
)
assert
.
NoError
(
t
,
err
)
assert
.
EqualValues
(
t
,
bcode
,
action
.
Code
)
}
if
test
.
IsCreate
{
assert
.
EqualValues
(
t
,
address
.
ExecAddress
(
types
.
ExecName
(
ExecutorName
)),
tx
.
To
)
}
else
{
assert
.
EqualValues
(
t
,
address
.
ExecAddress
(
types
.
ExecName
(
test
.
Name
)),
tx
.
To
)
}
}
}
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