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
c1ac0912
Commit
c1ac0912
authored
Apr 24, 2023
by
duanjinfei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
four commit
parent
c72a9be3
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
356 additions
and
320 deletions
+356
-320
app.json
config/app.json
+8
-8
contractConfig.json
config/contractConfig.json
+141
-142
main.go
main.go
+1
-1
noRelatedCase.go
operator/noRelatedCase.go
+32
-25
operator.go
operator/operator.go
+4
-4
partlyRelatedCase.go
operator/partlyRelatedCase.go
+129
-121
contract_test.go
test/contract_test.go
+14
-3
contract_util.go
util/contract_util.go
+27
-16
No files found.
config/app.json
View file @
c1ac0912
{
"deployAddr
1
"
:
"0xe2bA4B27E835f3D5A8f74B53aD6b8b6264D3F501"
,
"deployPrv
1
"
:
"115725efa0b457a764bb0b73b79a26605a54a5025d825b5a627f69354cdbbbf4"
,
"deployAddr"
:
"0x40EC4256fcBCA69CdbAc942594caeC79FBE10494"
,
"deployPrv"
:
"37871f094f89fc95599e73d72d3008c828bb76d0864759011fa14dbaf6cf3c06"
,
"rpcNode
1"
:
"http://192.168.1.125
:50000"
,
"rpcNode"
:
"http://15.161.177.5:26658"
,
"chainId
1
"
:
155
,
"chainId"
:
256256
,
"deployAddr"
:
"0xe2bA4B27E835f3D5A8f74B53aD6b8b6264D3F501"
,
"deployPrv"
:
"115725efa0b457a764bb0b73b79a26605a54a5025d825b5a627f69354cdbbbf4"
,
"deployAddr
1
"
:
"0x40EC4256fcBCA69CdbAc942594caeC79FBE10494"
,
"deployPrv
1
"
:
"37871f094f89fc95599e73d72d3008c828bb76d0864759011fa14dbaf6cf3c06"
,
"rpcNode
"
:
"http://54.72.101.87
:50000"
,
"rpcNode
1
"
:
"http://15.161.177.5:26658"
,
"chainId"
:
155
,
"chainId
1
"
:
256256
,
"goRoutine"
:
1
,
"generateAccCount"
:
500
,
"isDeployContract"
:
false
,
...
...
config/contractConfig.json
View file @
c1ac0912
This diff is collapsed.
Click to expand it.
main.go
View file @
c1ac0912
...
...
@@ -25,7 +25,7 @@ func main() {
// 转账交易case
if
len
(
tool
.
Cfg
.
TransferType
)
!=
0
{
accIndex
:=
0
accIndex
:=
12
nonceMap
:=
util
.
GetAccountNonce
(
tool
.
Cfg
.
RpcNode
)
arrFormat
:=
tool
.
ParseAccountConfig
(
"./config/account.json"
)
parseContractConfig
:=
tool
.
ParseContractConfig
(
"./config/contractConfig.json"
)
...
...
operator/noRelatedCase.go
View file @
c1ac0912
This diff is collapsed.
Click to expand it.
operator/operator.go
View file @
c1ac0912
...
...
@@ -73,8 +73,8 @@ func DeployContract(client *ethclient.Client, txRes []*types.Transaction) []*typ
}
auth
.
NoSend
=
true
auth
.
Value
=
big
.
NewInt
(
0
)
auth
.
GasLimit
=
uint64
(
5000
000000
)
auth
.
GasPrice
=
big
.
NewInt
(
5000
000000
)
auth
.
GasLimit
=
uint64
(
4
000000
)
auth
.
GasPrice
=
big
.
NewInt
(
4
000000
)
nonce
,
err
:=
client
.
NonceAt
(
context
.
Background
(),
tool
.
Cfg
.
DeployAddr
,
nil
)
if
err
!=
nil
{
log
.
Error
(
"DeployTokenTransfer func get acc nonce err:"
,
err
)
...
...
@@ -355,12 +355,12 @@ func GetTranFunc(caseType int, startIndex int, txCount int, nonceMap *sync.Map,
// 不相关-单层-Erc721转账
case
8
:
{
return
NrErc721TranCase
(
txCount
,
arr
,
contractArr
[
0
],
nonceMap
,
txArr
,
client
)
return
NrErc721TranCase
(
startIndex
,
txCount
,
arr
,
contractArr
[
0
],
nonceMap
,
txArr
,
client
)
}
// 不相关-多层-Erc721转账
case
9
:
{
return
NrOneErc721TranCase
(
txCount
,
arr
,
contractArr
[
0
],
nonceMap
,
txArr
,
client
)
return
NrOneErc721TranCase
(
startIndex
,
txCount
,
arr
,
contractArr
[
0
],
nonceMap
,
txArr
,
client
)
}
// 部分相关-普通转账-接受者相关
case
10
:
...
...
operator/partlyRelatedCase.go
View file @
c1ac0912
This diff is collapsed.
Click to expand it.
test/contract_test.go
View file @
c1ac0912
...
...
@@ -10,6 +10,7 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"math/big"
"strings"
"testing"
)
...
...
@@ -47,13 +48,13 @@ func TestGetContractAbi(t *testing.T) {
func
TestGetErc20Balance
(
t
*
testing
.
T
)
{
// 连接以太坊网络
client
,
err
:=
ethclient
.
Dial
(
"http://
15.161.177.5:26658
"
)
client
,
err
:=
ethclient
.
Dial
(
"http://
54.72.101.87:50000
"
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
// 从合约地址获取合约代码
contractAddress
:=
common
.
HexToAddress
(
"0x
91f2c122c8060258605c287cea0bdda056b7b25d
"
)
accountAddr
:=
common
.
HexToAddress
(
"0x
4b0ae7ac4886e7c54e40529cc008df84407e5975
"
)
contractAddress
:=
common
.
HexToAddress
(
"0x
14f2567347beb8ed0fec95397940f17ef7a94541
"
)
accountAddr
:=
common
.
HexToAddress
(
"0x
812D866f7f558A7325c16B729286e0e661b9DB36
"
)
newERC20
,
err
:=
erc20
.
NewERC20
(
contractAddress
,
client
)
if
err
!=
nil
{
...
...
@@ -86,3 +87,13 @@ func TestGetErc721Balance(t *testing.T) {
}
log
.
Info
(
"balance is :"
,
of
.
String
())
}
func
TestBigIntFunc
(
t
*
testing
.
T
)
{
//amount := big.NewInt(10000000000)
mul
:=
big
.
NewInt
(
1
)
.
Mul
(
big
.
NewInt
(
10000000000000000
),
big
.
NewInt
(
2
))
t
.
Log
(
"amount:"
,
mul
.
String
())
}
util/contract_util.go
View file @
c1ac0912
...
...
@@ -44,18 +44,28 @@ func HexToAddress(addr string) common.Address {
}
func
GetTxReceipt
(
client
*
ethclient
.
Client
,
txArr
[]
*
types
.
Transaction
)
{
txChanel
:=
make
(
chan
common
.
Hash
,
1000
)
for
i
:=
0
;
i
<
8
;
i
++
{
go
func
()
{
select
{
case
hash
:=
<-
txChanel
:
receipt
,
err
:=
client
.
TransactionReceipt
(
context
.
Background
(),
hash
)
if
err
!=
nil
{
log
.
Error
(
"Get tran receipt err:"
,
err
)
return
}
if
receipt
.
Status
==
0
{
log
.
Error
(
"Receipt:"
,
receipt
)
}
else
{
log
.
Infof
(
"Receipt: status: %d,gasUsed: %d"
,
receipt
.
Status
,
receipt
.
GasUsed
)
}
}
}()
}
for
_
,
tx
:=
range
txArr
{
receipt
,
err
:=
client
.
TransactionReceipt
(
context
.
Background
(),
tx
.
Hash
())
if
err
!=
nil
{
log
.
Error
(
"Get tran receipt err:"
,
err
)
return
}
if
receipt
.
Status
==
0
{
log
.
Error
(
"Receipt:"
,
receipt
)
}
else
{
log
.
Infof
(
"Receipt: status: %d,gasUsed: %d"
,
receipt
.
Status
,
receipt
.
GasUsed
)
}
txChanel
<-
tx
.
Hash
()
}
time
.
Sleep
(
time
.
Second
*
10
)
}
func
GetAccountNonce
(
client
*
ethclient
.
Client
)
*
sync
.
Map
{
...
...
@@ -115,7 +125,6 @@ func GetAccountBalance(client *ethclient.Client) {
select
{
case
addr
:=
<-
addrChan
:
GetAccBal
(
client
,
addr
)
log
.
Info
(
"tool.Cfg.ContractMap[0][constant.ERC20]:"
,
tool
.
Cfg
.
ContractMap
[
0
][
constant
.
ERC20
])
GetAccountErc20BalanceOf
(
client
,
tool
.
Cfg
.
ContractMap
[
0
][
constant
.
ERC20
],
addr
)
GetAccountErc721BalanceOf
(
client
,
tool
.
Cfg
.
ContractMap
[
0
][
constant
.
ERC721
],
addr
)
atomic
.
AddInt32
(
&
handleBalanceCount
,
1
)
...
...
@@ -147,11 +156,11 @@ func GetAccountErc20BalanceOf(client *ethclient.Client, erc20Addr common.Address
log
.
Errorf
(
"Get erc20 balance of failed err:%s"
,
err
.
Error
())
return
}
of
,
err
=
newERC20
.
Allowance
(
&
bind
.
CallOpts
{},
common
.
HexToAddress
(
"0xfb1bF24c0C7e7C1B89c4A496aACf01aBF26C0B94"
),
toAddr
)
if
err
!=
nil
{
log
.
Errorf
(
"Get erc20 balance of failed err:%s"
,
err
.
Error
())
return
}
//
of, err = newERC20.Allowance(&bind.CallOpts{}, common.HexToAddress("0xfb1bF24c0C7e7C1B89c4A496aACf01aBF26C0B94"), toAddr)
//
if err != nil {
//
log.Errorf("Get erc20 balance of failed err:%s", err.Error())
//
return
//
}
log
.
Infof
(
"%s erc20 balance of is: %s "
,
toAddr
.
Hash
()
.
Hex
(),
of
.
String
())
}
...
...
@@ -190,6 +199,7 @@ func ReadWriteCase(prv *ecdsa.PrivateKey, funcStr string, nonce *big.Int, readWr
}
auth
.
Nonce
=
nonce
auth
.
NoSend
=
true
auth
.
GasLimit
=
500000
auth
.
GasPrice
=
big
.
NewInt
(
1000000000000
)
tx
:=
&
types
.
Transaction
{}
switch
funcStr
{
...
...
@@ -269,6 +279,7 @@ func OneReadWriteCase(prv *ecdsa.PrivateKey, funcStr string, nonce *big.Int, rea
}
auth
.
Nonce
=
nonce
auth
.
NoSend
=
true
auth
.
GasLimit
=
500000
auth
.
GasPrice
=
big
.
NewInt
(
1000000000000
)
tx
:=
&
types
.
Transaction
{}
switch
funcStr
{
...
...
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