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
38b87fef
Commit
38b87fef
authored
Jan 26, 2019
by
jiangpeng
Committed by
vipwzw
Jan 27, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add unfreeze autotest
parent
ab7625a7
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
329 additions
and
0 deletions
+329
-0
create.go
plugin/dapp/unfreeze/autotest/create.go
+104
-0
terminate.go
plugin/dapp/unfreeze/autotest/terminate.go
+67
-0
unfreeze.go
plugin/dapp/unfreeze/autotest/unfreeze.go
+36
-0
unfreeze.toml
plugin/dapp/unfreeze/autotest/unfreeze.toml
+49
-0
withdraw.go
plugin/dapp/unfreeze/autotest/withdraw.go
+72
-0
plugin.go
plugin/dapp/unfreeze/plugin.go
+1
-0
No files found.
plugin/dapp/unfreeze/autotest/create.go
0 → 100644
View file @
38b87fef
// 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
(
"encoding/json"
"strconv"
"github.com/33cn/chain33/cmd/autotest/types"
)
type
fixAmountCase
struct
{
types
.
BaseCase
TotalAmount
string
`toml:"totalAmount"`
From
string
`toml:"from"`
To
string
`toml:"to"`
Period
int
`toml:"period"`
}
type
fixAmountPack
struct
{
types
.
BaseCasePack
info
*
unfreezeInfo
}
type
unfreezeInfo
struct
{
unFreezeID
string
period
int
}
// SendCommand send command
func
(
t
*
fixAmountCase
)
SendCommand
(
packID
string
)
(
types
.
PackFunc
,
error
)
{
return
types
.
DefaultSend
(
t
,
&
fixAmountPack
{},
packID
)
}
// GetCheckHandlerMap defines get check handle for map
func
(
pack
*
fixAmountPack
)
GetCheckHandlerMap
()
interface
{}
{
funcMap
:=
make
(
types
.
CheckHandlerMap
,
2
)
funcMap
[
"frozen"
]
=
pack
.
checkFrozen
funcMap
[
"unfreeze"
]
=
pack
.
checkUnfreeze
return
funcMap
}
// GetDependData defines get depend data function
func
(
pack
*
fixAmountPack
)
GetDependData
()
interface
{}
{
return
pack
.
info
}
func
(
pack
*
fixAmountPack
)
checkFrozen
(
txInfo
types
.
CheckHandlerParamType
)
bool
{
if
len
(
txInfo
.
Receipt
.
Logs
)
<
2
{
pack
.
FLog
.
Error
(
"checkFrozenLog"
,
"err"
,
"logNumLessThan 2"
)
return
false
}
var
frozenLog
map
[
string
]
interface
{}
err
:=
json
.
Unmarshal
(
txInfo
.
Receipt
.
Logs
[
1
]
.
Log
,
&
frozenLog
)
if
err
!=
nil
{
pack
.
FLog
.
Error
(
"checkFrozenLog"
,
"unmarshalErr"
,
err
)
}
interCase
:=
pack
.
TCase
.
(
*
fixAmountCase
)
amount
,
_
:=
strconv
.
ParseFloat
(
interCase
.
TotalAmount
,
64
)
b
:=
types
.
CheckFrozenDeltaWithAddr
(
frozenLog
,
interCase
.
From
,
amount
)
return
b
}
func
(
pack
*
fixAmountPack
)
checkUnfreeze
(
txInfo
types
.
CheckHandlerParamType
)
bool
{
var
freezeLog
map
[
string
]
interface
{}
err
:=
json
.
Unmarshal
(
txInfo
.
Receipt
.
Logs
[
2
]
.
Log
,
&
freezeLog
)
if
err
!=
nil
{
pack
.
FLog
.
Error
(
"checkUnfreeze"
,
"unmarshalErr"
,
err
)
}
interCase
:=
pack
.
TCase
.
(
*
fixAmountCase
)
info
:=
&
unfreezeInfo
{}
info
.
period
=
interCase
.
Period
info
.
unFreezeID
=
freezeLog
[
"current"
]
.
(
map
[
string
]
interface
{})[
"unfreezeID"
]
.
(
string
)
pack
.
info
=
info
amount
,
_
:=
strconv
.
ParseFloat
(
interCase
.
TotalAmount
,
64
)
total
,
_
:=
strconv
.
ParseFloat
(
freezeLog
[
"current"
]
.
(
map
[
string
]
interface
{})[
"totalCount"
]
.
(
string
),
64
)
remain
,
_
:=
strconv
.
ParseFloat
(
freezeLog
[
"current"
]
.
(
map
[
string
]
interface
{})[
"remaining"
]
.
(
string
),
64
)
amount
*=
1e8
if
types
.
IsBalanceEqualFloat
(
amount
,
total
)
&&
types
.
IsBalanceEqualFloat
(
amount
,
remain
)
&&
freezeLog
[
"current"
]
.
(
map
[
string
]
interface
{})[
"initiator"
]
.
(
string
)
==
interCase
.
From
&&
freezeLog
[
"current"
]
.
(
map
[
string
]
interface
{})[
"beneficiary"
]
.
(
string
)
==
interCase
.
To
{
return
true
}
return
false
}
plugin/dapp/unfreeze/autotest/terminate.go
0 → 100644
View file @
38b87fef
package
autotest
import
(
"encoding/json"
"fmt"
"strconv"
"github.com/33cn/chain33/cmd/autotest/types"
)
type
unfreezeTerminateCase
struct
{
types
.
BaseCase
Addr
string
`toml:"addr"`
info
*
unfreezeInfo
}
type
unfreezeTerminatePack
struct
{
types
.
BaseCasePack
}
// SendCommand defines send command
func
(
testCase
*
unfreezeTerminateCase
)
SendCommand
(
packID
string
)
(
types
.
PackFunc
,
error
)
{
if
testCase
.
info
==
nil
||
len
(
testCase
.
info
.
unFreezeID
)
==
0
{
return
nil
,
fmt
.
Errorf
(
"can't withdraw without unFreezeID"
)
}
testCase
.
Command
=
fmt
.
Sprintf
(
"%s --id %s"
,
testCase
.
Command
,
testCase
.
info
.
unFreezeID
)
return
types
.
DefaultSend
(
testCase
,
&
unfreezeTerminatePack
{},
packID
)
}
// SetDependData defines set depend data function
func
(
testCase
*
unfreezeTerminateCase
)
SetDependData
(
depData
interface
{})
{
if
info
,
ok
:=
depData
.
(
*
unfreezeInfo
);
ok
&&
info
!=
nil
{
testCase
.
info
=
info
}
}
// GetCheckHandlerMap defines get check handle for map
func
(
pack
*
unfreezeTerminatePack
)
GetCheckHandlerMap
()
interface
{}
{
funcMap
:=
make
(
types
.
CheckHandlerMap
,
1
)
funcMap
[
"unfreeze"
]
=
pack
.
checkUnfreeze
return
funcMap
}
func
(
pack
*
unfreezeTerminatePack
)
checkUnfreeze
(
txInfo
types
.
CheckHandlerParamType
)
bool
{
var
activeLog
map
[
string
]
interface
{}
var
freezeLog
map
[
string
]
interface
{}
err1
:=
json
.
Unmarshal
(
txInfo
.
Receipt
.
Logs
[
1
]
.
Log
,
&
activeLog
)
err2
:=
json
.
Unmarshal
(
txInfo
.
Receipt
.
Logs
[
2
]
.
Log
,
&
freezeLog
)
if
err1
!=
nil
||
err2
!=
nil
{
pack
.
FLog
.
Error
(
"checkUnfreeze"
,
"unmarshalErr1"
,
err1
,
"unmarshalErr2"
,
err2
)
}
interCase
:=
pack
.
TCase
.
(
*
unfreezeTerminateCase
)
freezePrev
,
_
:=
strconv
.
ParseFloat
(
freezeLog
[
"prev"
]
.
(
map
[
string
]
interface
{})[
"remaining"
]
.
(
string
),
64
)
freezeCurr
,
_
:=
strconv
.
ParseFloat
(
freezeLog
[
"current"
]
.
(
map
[
string
]
interface
{})[
"remaining"
]
.
(
string
),
64
)
delta
:=
(
freezeCurr
-
freezePrev
)
/
1e8
from
:=
freezeLog
[
"current"
]
.
(
map
[
string
]
interface
{})[
"initiator"
]
.
(
string
)
return
types
.
CheckFrozenDeltaWithAddr
(
activeLog
,
from
,
delta
)
&&
from
==
interCase
.
Addr
}
plugin/dapp/unfreeze/autotest/unfreeze.go
0 → 100644
View file @
38b87fef
// 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"
"github.com/33cn/chain33/system/dapp/coins/autotest"
)
type
unfreezeAutoTest
struct
{
SimpleCaseArr
[]
types
.
SimpleCase
`toml:"SimpleCase,omitempty"`
TransferCaseArr
[]
autotest
.
TransferCase
`toml:"TransferCase,omitempty"`
UnfreezeCreateFixArr
[]
fixAmountCase
`toml:"UnfreezeCreateFix,omitempty"`
UnfreezeWithdrawArr
[]
unfreezeWithdrawCase
`toml:"UnfreezeWithdraw,omitempty"`
UnfreezeTerminateArr
[]
unfreezeTerminateCase
`toml:"UnfreezeTerminate,omitempty"`
}
func
init
()
{
types
.
RegisterAutoTest
(
unfreezeAutoTest
{})
}
func
(
config
unfreezeAutoTest
)
GetName
()
string
{
return
"unfreeze"
}
func
(
config
unfreezeAutoTest
)
GetTestConfigType
()
reflect
.
Type
{
return
reflect
.
TypeOf
(
config
)
}
plugin/dapp/unfreeze/autotest/unfreeze.toml
0 → 100644
View file @
38b87fef
#send to unfreeze exec
[[TransferCase]]
id
=
"transUnfreeze"
command
=
"send bty transfer -a 5 -t 15YsqAuXeEXVHgm6RVx4oJaAAnhtwqnu3H -k 14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
from
=
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
to
=
"15YsqAuXeEXVHgm6RVx4oJaAAnhtwqnu3H"
amount
=
"5"
checkItem
=
["balance"]
[[UnfreezeCreateFix]]
id
=
"createFix"
command
=
"send unfreeze create fix_amount -a 0.01 -e coins -s bty -b 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv -p 1 -t 2 -k 14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
from
=
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
to
=
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
totalAmount
=
"2"
period
=
1
checkItem
=[
"frozen"
,
"unfreeze"
]
dep
=
["transUnfreeze"]
repeat
=
2
[[UnfreezeWithdraw]]
id
=
"withdraw"
command
=
"send unfreeze withdraw -k 12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
addr
=
"12qyocayNF7Lv6C9qW4avxs2E7U41fKSfv"
checkItem
=
["unfreeze"]
dep
=
["createFix"]
[[UnfreezeTerminate]]
id
=
"terminate"
command
=
"send unfreeze terminate -k 14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
addr
=
"14KEKbYtKKQm4wMthSK9J4La4nAiidGozt"
checkItem
=
["unfreeze"]
dep
=
[
"createFix"
,
"withdraw"
]
plugin/dapp/unfreeze/autotest/withdraw.go
0 → 100644
View file @
38b87fef
package
autotest
import
(
"encoding/json"
"fmt"
"strconv"
"time"
"github.com/33cn/chain33/cmd/autotest/types"
)
type
unfreezeWithdrawCase
struct
{
types
.
BaseCase
Addr
string
`toml:"addr"`
info
*
unfreezeInfo
}
type
unfreezeWithdrawPack
struct
{
types
.
BaseCasePack
}
// SendCommand defines send command
func
(
testCase
*
unfreezeWithdrawCase
)
SendCommand
(
packID
string
)
(
types
.
PackFunc
,
error
)
{
if
testCase
.
info
==
nil
||
len
(
testCase
.
info
.
unFreezeID
)
==
0
{
return
nil
,
fmt
.
Errorf
(
"can't withdraw without unFreezeID"
)
}
time
.
Sleep
(
time
.
Second
*
time
.
Duration
(
testCase
.
info
.
period
))
return
types
.
DefaultSend
(
testCase
,
&
unfreezeWithdrawPack
{},
packID
)
}
// SetDependData defines set depend data function
func
(
testCase
*
unfreezeWithdrawCase
)
SetDependData
(
depData
interface
{})
{
if
info
,
ok
:=
depData
.
(
*
unfreezeInfo
);
ok
&&
info
!=
nil
{
testCase
.
info
=
info
testCase
.
Command
=
fmt
.
Sprintf
(
"%s --id %s"
,
testCase
.
Command
,
testCase
.
info
.
unFreezeID
)
}
}
// GetCheckHandlerMap defines get check handle for map
func
(
pack
*
unfreezeWithdrawPack
)
GetCheckHandlerMap
()
interface
{}
{
funcMap
:=
make
(
types
.
CheckHandlerMap
,
1
)
funcMap
[
"unfreeze"
]
=
pack
.
checkUnfreeze
return
funcMap
}
func
(
pack
*
unfreezeWithdrawPack
)
checkUnfreeze
(
txInfo
types
.
CheckHandlerParamType
)
bool
{
var
fromLog
map
[
string
]
interface
{}
var
toLog
map
[
string
]
interface
{}
var
freezeLog
map
[
string
]
interface
{}
err1
:=
json
.
Unmarshal
(
txInfo
.
Receipt
.
Logs
[
1
]
.
Log
,
&
fromLog
)
err2
:=
json
.
Unmarshal
(
txInfo
.
Receipt
.
Logs
[
2
]
.
Log
,
&
toLog
)
err3
:=
json
.
Unmarshal
(
txInfo
.
Receipt
.
Logs
[
3
]
.
Log
,
&
freezeLog
)
if
err1
!=
nil
||
err2
!=
nil
||
err3
!=
nil
{
pack
.
FLog
.
Error
(
"checkUnfreeze"
,
"unmarshalErr1"
,
err1
,
"unmarshalErr2"
,
err2
,
"unmarshalErr3"
,
err3
)
}
interCase
:=
pack
.
TCase
.
(
*
unfreezeWithdrawCase
)
freezePrev
,
_
:=
strconv
.
ParseFloat
(
freezeLog
[
"prev"
]
.
(
map
[
string
]
interface
{})[
"remaining"
]
.
(
string
),
64
)
freezeCurr
,
_
:=
strconv
.
ParseFloat
(
freezeLog
[
"current"
]
.
(
map
[
string
]
interface
{})[
"remaining"
]
.
(
string
),
64
)
delta
:=
(
freezeCurr
-
freezePrev
)
/
1e8
from
:=
freezeLog
[
"current"
]
.
(
map
[
string
]
interface
{})[
"initiator"
]
.
(
string
)
to
:=
freezeLog
[
"current"
]
.
(
map
[
string
]
interface
{})[
"beneficiary"
]
.
(
string
)
return
types
.
CheckFrozenDeltaWithAddr
(
fromLog
,
from
,
delta
)
&&
types
.
CheckBalanceDeltaWithAddr
(
toLog
,
to
,
-
delta
)
&&
to
==
interCase
.
Addr
}
plugin/dapp/unfreeze/plugin.go
View file @
38b87fef
...
...
@@ -6,6 +6,7 @@ package unfreeze
import
(
"github.com/33cn/chain33/pluginmgr"
_
"github.com/33cn/plugin/plugin/dapp/unfreeze/autotest"
// register autotest package
"github.com/33cn/plugin/plugin/dapp/unfreeze/commands"
"github.com/33cn/plugin/plugin/dapp/unfreeze/executor"
"github.com/33cn/plugin/plugin/dapp/unfreeze/rpc"
...
...
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