Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
contract-case
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
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
duanjinfei
contract-case
Commits
c7e1fe00
Commit
c7e1fe00
authored
Jun 08, 2023
by
duanjinfei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix chain evm problem and add case
parent
0b1adad5
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
39 additions
and
14 deletions
+39
-14
app.json
config/app.json
+2
-0
main.go
main.go
+4
-2
operator.go
operator/operator.go
+11
-0
partlyRelatedCase.go
operator/partlyRelatedCase.go
+12
-8
contract_test.go
test/contract_test.go
+4
-4
Config.go
tool/Config.go
+6
-0
No files found.
config/app.json
View file @
c7e1fe00
...
@@ -20,7 +20,9 @@
...
@@ -20,7 +20,9 @@
"endTokenId"
:
100
,
"endTokenId"
:
100
,
"accStartIndex"
:
0
,
"accStartIndex"
:
0
,
"sendTranAfterSleep"
:
120
,
"sendTranAfterSleep"
:
120
,
"everyCaseTxCount"
:
1
,
"isGetAccBalance"
:
false
,
"isGetAccBalance"
:
false
,
"isUseNotSameAcc"
:
false
,
"transferType"
:
[
29
]
"transferType"
:
[
29
]
}
}
...
...
main.go
View file @
c7e1fe00
...
@@ -30,15 +30,17 @@ func main() {
...
@@ -30,15 +30,17 @@ func main() {
arrFormat
:=
tool
.
ParseAccountConfig
(
"./config/account.json"
)
arrFormat
:=
tool
.
ParseAccountConfig
(
"./config/account.json"
)
parseContractConfig
:=
tool
.
ParseContractConfig
(
"./config/contractConfig.json"
)
parseContractConfig
:=
tool
.
ParseContractConfig
(
"./config/contractConfig.json"
)
for
_
,
caseType
:=
range
tool
.
Cfg
.
TransferType
{
for
_
,
caseType
:=
range
tool
.
Cfg
.
TransferType
{
tranList
,
verifyFunc
:=
operator
.
GetTranFunc
(
caseType
,
accIndex
,
9
,
nonceMap
,
arrFormat
,
tool
.
Cfg
.
RpcNode
,
parseContractConfig
)
tranList
,
verifyFunc
:=
operator
.
GetTranFunc
(
caseType
,
accIndex
,
tool
.
Cfg
.
EveryCaseTxCount
,
nonceMap
,
arrFormat
,
tool
.
Cfg
.
RpcNode
,
parseContractConfig
)
if
tranList
==
nil
||
verifyFunc
==
nil
{
if
tranList
==
nil
||
verifyFunc
==
nil
{
break
break
}
}
txArr
=
append
(
txArr
,
tranList
...
)
txArr
=
append
(
txArr
,
tranList
...
)
verifyFuncArr
=
append
(
verifyFuncArr
,
verifyFunc
)
verifyFuncArr
=
append
(
verifyFuncArr
,
verifyFunc
)
if
tool
.
Cfg
.
IsUseNotSameAcc
{
accIndex
+=
9
accIndex
+=
9
}
}
}
}
}
// 发送整合后的交易
// 发送整合后的交易
if
len
(
txArr
)
>
0
{
if
len
(
txArr
)
>
0
{
...
...
operator/operator.go
View file @
c7e1fe00
...
@@ -209,6 +209,15 @@ func InitErc721AccTransfer(txArr []*types.Transaction, nonce uint64, contractLen
...
@@ -209,6 +209,15 @@ func InitErc721AccTransfer(txArr []*types.Transaction, nonce uint64, contractLen
return
nil
,
0
return
nil
,
0
}
}
txArr
=
append
(
txArr
,
tx
)
txArr
=
append
(
txArr
,
tx
)
nonce
+=
1
auth
.
Nonce
=
big
.
NewInt
(
int64
(
nonce
))
tx
,
err
=
newERC721
.
SetApprovalForAllFrom
(
auth
,
accArr
.
ToAddr
[
i
],
contractMap
[
j
][
constant
.
TOKEN721_TRANSFER
],
true
)
if
err
!=
nil
{
log
.
Error
(
"Init account - erc721 setApprovalForAllFrom err:"
,
err
.
Error
())
return
nil
,
0
}
txArr
=
append
(
txArr
,
tx
)
log
.
Info
(
"Init account - transferFrom 721 successful,tx:"
,
tx
.
Hash
()
.
Hex
())
log
.
Info
(
"Init account - transferFrom 721 successful,tx:"
,
tx
.
Hash
()
.
Hex
())
nonce
+=
1
nonce
+=
1
}
}
...
@@ -290,6 +299,8 @@ func InitCaseAccount(client *ethclient.Client, txArr []*types.Transaction) []*ty
...
@@ -290,6 +299,8 @@ func InitCaseAccount(client *ethclient.Client, txArr []*types.Transaction) []*ty
accArr
:=
tool
.
ParseAccountConfig
(
"./config/account.json"
)
accArr
:=
tool
.
ParseAccountConfig
(
"./config/account.json"
)
auth
,
err
:=
bind
.
NewKeyedTransactorWithChainID
(
tool
.
Cfg
.
DeployPrv
,
tool
.
Cfg
.
ChainId
)
auth
,
err
:=
bind
.
NewKeyedTransactorWithChainID
(
tool
.
Cfg
.
DeployPrv
,
tool
.
Cfg
.
ChainId
)
auth
.
NoSend
=
true
auth
.
NoSend
=
true
auth
.
GasLimit
=
500000
auth
.
GasPrice
=
big
.
NewInt
(
10000000000
)
amount
:=
big
.
NewInt
(
0
)
amount
:=
big
.
NewInt
(
0
)
amount
.
SetString
(
"10000000000000000000"
,
10
)
amount
.
SetString
(
"10000000000000000000"
,
10
)
trade
:=
&
coin
.
Trade
{
trade
:=
&
coin
.
Trade
{
...
...
operator/partlyRelatedCase.go
View file @
c7e1fe00
...
@@ -1080,6 +1080,7 @@ func PrReOneErc20TranCase(txCount int, testAccArr *tool.AccArrFormat, contractMa
...
@@ -1080,6 +1080,7 @@ func PrReOneErc20TranCase(txCount int, testAccArr *tool.AccArrFormat, contractMa
beforeAddrErc20Bal
[
testAccArr
.
FromAddr
[
i
]]
=
fromBal
beforeAddrErc20Bal
[
testAccArr
.
FromAddr
[
i
]]
=
fromBal
oneErc20Trade
.
ToAddr
=
[]
common
.
Address
{
testAccArr
.
ToAddr
[
i
]}
oneErc20Trade
.
ToAddr
=
[]
common
.
Address
{
testAccArr
.
ToAddr
[
i
]}
oneErc20Trade
.
FromAddr
=
testAccArr
.
FromAddr
[
i
]
auth
,
err
:=
bind
.
NewKeyedTransactorWithChainID
(
testAccArr
.
FromPrv
[
i
],
tool
.
Cfg
.
ChainId
)
auth
,
err
:=
bind
.
NewKeyedTransactorWithChainID
(
testAccArr
.
FromPrv
[
i
],
tool
.
Cfg
.
ChainId
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Errorf
(
"DeployTokenTransfer func newKeyedTransactorWithChainID err:"
,
err
)
log
.
Errorf
(
"DeployTokenTransfer func newKeyedTransactorWithChainID err:"
,
err
)
...
@@ -1106,6 +1107,7 @@ func PrReOneErc20TranCase(txCount int, testAccArr *tool.AccArrFormat, contractMa
...
@@ -1106,6 +1107,7 @@ func PrReOneErc20TranCase(txCount int, testAccArr *tool.AccArrFormat, contractMa
}
}
log
.
Infof
(
"ERC20 After to addr:%s,toBal:%s"
,
testAccArr
.
ToAddr
[
i
]
.
Hex
(),
to
.
String
())
log
.
Infof
(
"ERC20 After to addr:%s,toBal:%s"
,
testAccArr
.
ToAddr
[
i
]
.
Hex
(),
to
.
String
())
if
to
.
Sub
(
to
,
beforeAddrErc20Bal
[
testAccArr
.
ToAddr
[
i
]])
.
Cmp
(
amount
)
!=
0
{
if
to
.
Sub
(
to
,
beforeAddrErc20Bal
[
testAccArr
.
ToAddr
[
i
]])
.
Cmp
(
amount
)
!=
0
{
log
.
Error
(
"To addr balance verify failed"
)
res
=
false
res
=
false
}
}
...
@@ -1115,7 +1117,8 @@ func PrReOneErc20TranCase(txCount int, testAccArr *tool.AccArrFormat, contractMa
...
@@ -1115,7 +1117,8 @@ func PrReOneErc20TranCase(txCount int, testAccArr *tool.AccArrFormat, contractMa
log
.
Error
(
"Get erc20 balanceOf error:"
,
err
.
Error
())
log
.
Error
(
"Get erc20 balanceOf error:"
,
err
.
Error
())
res
=
false
res
=
false
}
}
if
beforeAddrErc20Bal
[
testAccArr
.
FromAddr
[
i
]]
.
Sub
(
beforeAddrErc20Bal
[
testAccArr
.
FromAddr
[
i
]],
from
)
.
Cmp
(
amount
)
!=
1
{
if
beforeAddrErc20Bal
[
testAccArr
.
FromAddr
[
i
]]
.
Sub
(
beforeAddrErc20Bal
[
testAccArr
.
FromAddr
[
i
]],
from
)
.
Cmp
(
amount
)
!=
0
{
log
.
Error
(
"From addr balance verify failed"
)
res
=
false
res
=
false
}
}
}
}
...
@@ -1159,6 +1162,7 @@ func PrReOneErc20TranCase1(txCount int, testAccArr *tool.AccArrFormat, contractM
...
@@ -1159,6 +1162,7 @@ func PrReOneErc20TranCase1(txCount int, testAccArr *tool.AccArrFormat, contractM
log
.
Infof
(
"ERC20 Before from addr:%s,fromBal:%s"
,
testAccArr
.
FromAddr
[
i
]
.
Hex
(),
fromBal
.
String
())
log
.
Infof
(
"ERC20 Before from addr:%s,fromBal:%s"
,
testAccArr
.
FromAddr
[
i
]
.
Hex
(),
fromBal
.
String
())
beforeAddrErc20Bal
[
testAccArr
.
FromAddr
[
i
]]
=
fromBal
beforeAddrErc20Bal
[
testAccArr
.
FromAddr
[
i
]]
=
fromBal
oneErc20Trade
.
ToAddr
=
[]
common
.
Address
{
toAddr
}
oneErc20Trade
.
ToAddr
=
[]
common
.
Address
{
toAddr
}
oneErc20Trade
.
FromAddr
=
testAccArr
.
FromAddr
[
i
]
auth
,
err
:=
bind
.
NewKeyedTransactorWithChainID
(
testAccArr
.
FromPrv
[
i
],
tool
.
Cfg
.
ChainId
)
auth
,
err
:=
bind
.
NewKeyedTransactorWithChainID
(
testAccArr
.
FromPrv
[
i
],
tool
.
Cfg
.
ChainId
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Errorf
(
"DeployTokenTransfer func newKeyedTransactorWithChainID err:"
,
err
)
log
.
Errorf
(
"DeployTokenTransfer func newKeyedTransactorWithChainID err:"
,
err
)
...
@@ -1193,7 +1197,7 @@ func PrReOneErc20TranCase1(txCount int, testAccArr *tool.AccArrFormat, contractM
...
@@ -1193,7 +1197,7 @@ func PrReOneErc20TranCase1(txCount int, testAccArr *tool.AccArrFormat, contractM
res
=
false
res
=
false
}
}
log
.
Infof
(
"ERC20 After from addr:%s,fromBal:%s"
,
testAccArr
.
FromAddr
[
i
]
.
Hex
(),
from
.
String
())
log
.
Infof
(
"ERC20 After from addr:%s,fromBal:%s"
,
testAccArr
.
FromAddr
[
i
]
.
Hex
(),
from
.
String
())
if
beforeAddrErc20Bal
[
testAccArr
.
FromAddr
[
i
]]
.
Sub
(
beforeAddrErc20Bal
[
testAccArr
.
FromAddr
[
i
]],
from
)
.
Cmp
(
amount
)
!=
1
{
if
beforeAddrErc20Bal
[
testAccArr
.
FromAddr
[
i
]]
.
Sub
(
beforeAddrErc20Bal
[
testAccArr
.
FromAddr
[
i
]],
from
)
.
Cmp
(
amount
)
!=
0
{
res
=
false
res
=
false
}
}
}
}
...
@@ -1295,8 +1299,8 @@ func PrReErc721TranCase(startIndex int, txCount int, testAccArr *tool.AccArrForm
...
@@ -1295,8 +1299,8 @@ func PrReErc721TranCase(startIndex int, txCount int, testAccArr *tool.AccArrForm
value
,
_
:=
accountNonceMap
.
Load
(
testAccArr
.
FromAddr
[
i
])
value
,
_
:=
accountNonceMap
.
Load
(
testAccArr
.
FromAddr
[
i
])
auth
.
Nonce
=
big
.
NewInt
(
value
.
(
int64
))
auth
.
Nonce
=
big
.
NewInt
(
value
.
(
int64
))
auth
.
NoSend
=
true
auth
.
NoSend
=
true
auth
.
GasLimit
=
5
00000
auth
.
GasLimit
=
60
00000
auth
.
GasPrice
=
big
.
NewInt
(
1
0000000000
)
auth
.
GasPrice
=
big
.
NewInt
(
20
0000000000
)
tx
,
err
:=
erc721Trade
.
Erc721TransferFromSignTx
(
auth
,
tokenTransfer
)
tx
,
err
:=
erc721Trade
.
Erc721TransferFromSignTx
(
auth
,
tokenTransfer
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Error
(
"Erc721TransferFromSignTx error:"
,
err
.
Error
())
log
.
Error
(
"Erc721TransferFromSignTx error:"
,
err
.
Error
())
...
@@ -1384,8 +1388,8 @@ func PrReErc721TranFromCase(startIndex int, txCount int, testAccArr *tool.AccArr
...
@@ -1384,8 +1388,8 @@ func PrReErc721TranFromCase(startIndex int, txCount int, testAccArr *tool.AccArr
erc721Trade
.
TokenId
=
big
.
NewInt
(
int64
(
startIndex
))
erc721Trade
.
TokenId
=
big
.
NewInt
(
int64
(
startIndex
))
auth
.
Nonce
=
big
.
NewInt
(
nonce
)
auth
.
Nonce
=
big
.
NewInt
(
nonce
)
auth
.
NoSend
=
true
auth
.
NoSend
=
true
auth
.
GasLimit
=
500000
auth
.
GasLimit
=
500000
0
auth
.
GasPrice
=
big
.
NewInt
(
10000000000
)
auth
.
GasPrice
=
big
.
NewInt
(
10000000000
0
)
tx
,
err
:=
erc721Trade
.
Erc721TransferFromSignTx
(
auth
,
tokenTransfer
)
tx
,
err
:=
erc721Trade
.
Erc721TransferFromSignTx
(
auth
,
tokenTransfer
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Error
(
"Erc721TransferFromSignTx error:"
,
err
.
Error
())
log
.
Error
(
"Erc721TransferFromSignTx error:"
,
err
.
Error
())
...
@@ -1404,7 +1408,7 @@ func PrReErc721TranFromCase(startIndex int, txCount int, testAccArr *tool.AccArr
...
@@ -1404,7 +1408,7 @@ func PrReErc721TranFromCase(startIndex int, txCount int, testAccArr *tool.AccArr
log
.
Error
(
"Get erc721 bal error:"
,
err
.
Error
())
log
.
Error
(
"Get erc721 bal error:"
,
err
.
Error
())
res
=
false
res
=
false
}
}
log
.
Info
(
"Erc721
接受
者相关 From balance:"
,
fromErc721Bal
.
String
())
log
.
Info
(
"Erc721
发送
者相关 From balance:"
,
fromErc721Bal
.
String
())
if
beforeFromErc721Bal
.
Sub
(
beforeFromErc721Bal
,
fromErc721Bal
)
.
Cmp
(
big
.
NewInt
(
int64
(
txCount
)))
!=
0
{
if
beforeFromErc721Bal
.
Sub
(
beforeFromErc721Bal
,
fromErc721Bal
)
.
Cmp
(
big
.
NewInt
(
int64
(
txCount
)))
!=
0
{
res
=
false
res
=
false
}
}
...
@@ -1415,7 +1419,7 @@ func PrReErc721TranFromCase(startIndex int, txCount int, testAccArr *tool.AccArr
...
@@ -1415,7 +1419,7 @@ func PrReErc721TranFromCase(startIndex int, txCount int, testAccArr *tool.AccArr
log
.
Error
(
"Get erc721 bal error:"
,
err
.
Error
())
log
.
Error
(
"Get erc721 bal error:"
,
err
.
Error
())
res
=
false
res
=
false
}
}
log
.
Info
(
"Erc721
接受
者相关 To balance:"
,
toErc721Bal
.
String
())
log
.
Info
(
"Erc721
发送
者相关 To balance:"
,
toErc721Bal
.
String
())
if
toErc721Bal
.
Sub
(
toErc721Bal
,
beforeToErc721Bal
[
receiveToAddr
])
.
Cmp
(
big
.
NewInt
(
1
))
!=
0
{
if
toErc721Bal
.
Sub
(
toErc721Bal
,
beforeToErc721Bal
[
receiveToAddr
])
.
Cmp
(
big
.
NewInt
(
1
))
!=
0
{
res
=
false
res
=
false
}
}
...
...
test/contract_test.go
View file @
c7e1fe00
...
@@ -14,12 +14,12 @@ import (
...
@@ -14,12 +14,12 @@ import (
func
TestGetContractAbi
(
t
*
testing
.
T
)
{
func
TestGetContractAbi
(
t
*
testing
.
T
)
{
// 连接以太坊网络
// 连接以太坊网络
client
,
err
:=
ethclient
.
Dial
(
"http://
54.72.101.87
:50000"
)
client
,
err
:=
ethclient
.
Dial
(
"http://
192.168.1.114
:50000"
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Fatal
(
err
)
log
.
Fatal
(
err
)
}
}
// 从合约地址获取合约代码
// 从合约地址获取合约代码
contractAddress
:=
common
.
HexToAddress
(
"0x
fb1bF24c0C7e7C1B89c4A496aACf01aBF26C0B9
4"
)
contractAddress
:=
common
.
HexToAddress
(
"0x
502336Ad1DABCa0F3C06098F72E79265D66bC37
4"
)
//code, err := client.CodeAt(context.Background(), contractAddress, nil)
//code, err := client.CodeAt(context.Background(), contractAddress, nil)
//if err != nil {
//if err != nil {
...
@@ -41,12 +41,12 @@ func TestGetContractAbi(t *testing.T) {
...
@@ -41,12 +41,12 @@ func TestGetContractAbi(t *testing.T) {
}
}
log
.
Info
(
"balance:"
,
balance
.
String
())
log
.
Info
(
"balance:"
,
balance
.
String
())
receipt
,
err
:=
client
.
TransactionReceipt
(
context
.
Background
(),
common
.
HexToHash
(
"0x
478828957ad9314d1d11e36d0a94142b89df6c74d4688d396a06953fdaa998c5
"
))
receipt
,
err
:=
client
.
TransactionReceipt
(
context
.
Background
(),
common
.
HexToHash
(
"0x
732f529095537e2abb13a4737693cb6d740531bc05bd0fb2fee3a1ebd8893ebf
"
))
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Fatal
(
"Get receipt error:"
,
err
.
Error
())
log
.
Fatal
(
"Get receipt error:"
,
err
.
Error
())
return
return
}
}
log
.
Info
(
"status:"
,
receipt
.
Status
,
",tranNonce:"
,
receipt
.
TransactionIndex
,
",GasUsed:"
,
receipt
.
GasUsed
)
log
.
Info
(
"status:"
,
receipt
.
Status
,
",tranNonce:"
,
receipt
.
TransactionIndex
,
",GasUsed:"
,
receipt
.
GasUsed
,
",blockNumber:"
,
receipt
.
BlockNumber
,
",logs:"
,
receipt
.
Logs
)
}
}
func
TestGetErc20Balance
(
t
*
testing
.
T
)
{
func
TestGetErc20Balance
(
t
*
testing
.
T
)
{
...
...
tool/Config.go
View file @
c7e1fe00
...
@@ -30,6 +30,8 @@ type ConfigJson struct {
...
@@ -30,6 +30,8 @@ type ConfigJson struct {
AccStartIndex
int
`json:"accStartIndex"`
AccStartIndex
int
`json:"accStartIndex"`
SendTranAfterSleep
int
`json:"sendTranAfterSleep"`
SendTranAfterSleep
int
`json:"sendTranAfterSleep"`
IsGetAccBalance
bool
`json:"isGetAccBalance"`
IsGetAccBalance
bool
`json:"isGetAccBalance"`
IsUseNotSameAcc
bool
`json:"isUseNotSameAcc"`
EveryCaseTxCount
int
`json:"everyCaseTxCount"`
}
}
type
Config
struct
{
type
Config
struct
{
...
@@ -50,6 +52,8 @@ type Config struct {
...
@@ -50,6 +52,8 @@ type Config struct {
AccStartIndex
int
AccStartIndex
int
SendTranAfterSleep
int
SendTranAfterSleep
int
IsGetAccBalance
bool
IsGetAccBalance
bool
IsUseNotSameAcc
bool
EveryCaseTxCount
int
}
}
type
AccArr
struct
{
type
AccArr
struct
{
...
@@ -117,6 +121,8 @@ func ParseConfig(path string) {
...
@@ -117,6 +121,8 @@ func ParseConfig(path string) {
AccStartIndex
:
cfgJson
.
AccStartIndex
,
AccStartIndex
:
cfgJson
.
AccStartIndex
,
SendTranAfterSleep
:
cfgJson
.
SendTranAfterSleep
,
SendTranAfterSleep
:
cfgJson
.
SendTranAfterSleep
,
IsGetAccBalance
:
cfgJson
.
IsGetAccBalance
,
IsGetAccBalance
:
cfgJson
.
IsGetAccBalance
,
IsUseNotSameAcc
:
cfgJson
.
IsUseNotSameAcc
,
EveryCaseTxCount
:
cfgJson
.
EveryCaseTxCount
,
}
}
}
}
...
...
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