Skip to content

Commit

Permalink
update UT
Browse files Browse the repository at this point in the history
  • Loading branch information
studyzy committed Aug 19, 2019
1 parent 814a7d6 commit 0daa72d
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 60 deletions.
8 changes: 4 additions & 4 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
kind: pipeline
name: default
steps:
- name: test
image: golang
commands:
- go test -mod=vendor .
- name: lint
image: golang
commands:
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.17.1
- golangci-lint run .
- name: test
image: golang
commands:
- go test -mod=vendor .
14 changes: 8 additions & 6 deletions AdaptorETH.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,23 @@ type RPCParams struct {
type AdaptorETH struct {
NetID int
RPCParams
lockContractAddress string
//lockContractAddress string
}

func NewAdaptorETHTestnet() *AdaptorETH {
return &AdaptorETH{
NetID: NETID_TEST,
RPCParams: RPCParams{Rawurl: "https://ropsten.infura.io",
TxQueryUrl: "https://api-ropsten.etherscan.io/api"},
lockContractAddress:"0x4d736ed88459b2db85472aab13a9d0ce2a6ea676",
//lockContractAddress:"0x4d736ed88459b2db85472aab13a9d0ce2a6ea676",
}
}
func NewAdaptorETHMainnet() *AdaptorETH {
return &AdaptorETH{
NetID: NETID_MAIN,
RPCParams: RPCParams{Rawurl: "https://mainnet.infura.io",
TxQueryUrl:"https://api.etherscan.io/api"},
lockContractAddress:"0x1989a21eb0f28063e47e6b448e8d76774bc9b493",
//lockContractAddress:"0x1989a21eb0f28063e47e6b448e8d76774bc9b493",
}
}

Expand Down Expand Up @@ -87,7 +87,10 @@ func (aeth *AdaptorETH) GetAddress(key *adaptor.GetAddressInput) (*adaptor.GetAd
return &result, nil
}
func (aeth *AdaptorETH) GetPalletOneMappingAddress(addr *adaptor.GetPalletOneMappingAddressInput) (*adaptor.GetPalletOneMappingAddressOutput, error) {
return GetMappAddr(addr, &aeth.RPCParams, aeth.lockContractAddress)
if len(addr.MappingDataSource)==0{
return nil,errors.New("You must define mapping contract address in MappingDataSource")
}
return GetMappAddr(addr, &aeth.RPCParams, addr.MappingDataSource)
}

//对一条消息进行签名
Expand Down Expand Up @@ -169,8 +172,7 @@ func (aeth *AdaptorETH) GetTransferTx(input *adaptor.GetTransferTxInput) (*adapt

//创建一个多签地址,该地址必须要满足signCount个签名才能解锁 //eth没有多签,not implement
func (aeth *AdaptorETH) CreateMultiSigAddress(input *adaptor.CreateMultiSigAddressInput) (*adaptor.CreateMultiSigAddressOutput, error) {

return &adaptor.CreateMultiSigAddressOutput{Address: aeth.lockContractAddress}, nil
return nil, errors.New("Please deploy multi-sign contract yourself.")
}

/*ISmartContract*/
Expand Down
19 changes: 12 additions & 7 deletions AdaptorErc20.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package ethadaptor

import (
"errors"
"fmt"
"strconv"

Expand All @@ -29,26 +30,26 @@ import (
type AdaptorErc20 struct {
NetID int
RPCParams
lockContractAddress string
//lockContractAddress string
}

func NewAdaptorErc20(netID int, rPCParams RPCParams, lockAddress string) *AdaptorErc20 {
return &AdaptorErc20{netID, rPCParams, lockAddress}
func NewAdaptorErc20(netID int, rPCParams RPCParams ) *AdaptorErc20 {
return &AdaptorErc20{netID, rPCParams}
}
func NewAdaptorErc20Testnet() *AdaptorErc20 {
return &AdaptorErc20{
NetID: NETID_TEST,
RPCParams: RPCParams{Rawurl: "https://ropsten.infura.io",
TxQueryUrl: "https://api-ropsten.etherscan.io/api"},
lockContractAddress: "0x4d736ed88459b2db85472aab13a9d0ce2a6ea676",
//lockContractAddress: "0x4d736ed88459b2db85472aab13a9d0ce2a6ea676",
}
}
func NewAdaptorErc20Mainnet() *AdaptorErc20 {
return &AdaptorErc20{
NetID: NETID_MAIN,
RPCParams: RPCParams{Rawurl: "https://mainnet.infura.io",
TxQueryUrl: "https://api.etherscan.io/api"},
lockContractAddress: "0x1989a21eb0f28063e47e6b448e8d76774bc9b493",
//lockContractAddress: "0x1989a21eb0f28063e47e6b448e8d76774bc9b493",
}
}

Expand Down Expand Up @@ -163,7 +164,10 @@ func GetMappAddr(addr *adaptor.GetPalletOneMappingAddressInput,
return &result, nil
}
func (aerc20 *AdaptorErc20) GetPalletOneMappingAddress(addr *adaptor.GetPalletOneMappingAddressInput) (*adaptor.GetPalletOneMappingAddressOutput, error) {
return GetMappAddr(addr, &aerc20.RPCParams, aerc20.lockContractAddress)
if len(addr.MappingDataSource)==0{
return nil,errors.New("You must define mapping contract address in MappingDataSource")
}
return GetMappAddr(addr, &aerc20.RPCParams, addr.MappingDataSource)
}

//对一条交易进行签名,并返回签名结果
Expand Down Expand Up @@ -273,7 +277,8 @@ func (aerc20 *AdaptorErc20) GetTransferTx(input *adaptor.GetTransferTxInput) (*a

//创建一个多签地址,该地址必须要满足signCount个签名才能解锁
func (aerc20 *AdaptorErc20) CreateMultiSigAddress(input *adaptor.CreateMultiSigAddressInput) (*adaptor.CreateMultiSigAddressOutput, error) {
return &adaptor.CreateMultiSigAddressOutput{Address: aerc20.lockContractAddress}, nil
//return &adaptor.CreateMultiSigAddressOutput{Address: aerc20.lockContractAddress}, nil
return nil, errors.New("Please deploy multi-sign contract yourself.")
}

//获取最新区块头
Expand Down
12 changes: 8 additions & 4 deletions AdaptorErc20_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func newTestAdaptorErc20() *AdaptorErc20 {
rpcParams := RPCParams{
Rawurl: "https://ropsten.infura.io/", //"\\\\.\\pipe\\geth.ipc",//0xfb686ccee357012b8b8f338f8266a472f3c211c82f0a4c30a5d2e51176556546
}
return NewAdaptorErc20(NETID_TEST, rpcParams, "")
return NewAdaptorErc20(NETID_TEST, rpcParams)
}

func TestGetAssetDecimal(t *testing.T) {
Expand All @@ -40,14 +40,18 @@ func TestAdaptorErc20_GetPalletOneMappingAddress(t *testing.T) {
Rawurl: "https://ropsten.infura.io/", //"\\\\.\\pipe\\geth.ipc",//0xfb686ccee357012b8b8f338f8266a472f3c211c82f0a4c30a5d2e51176556546
}

ada := NewAdaptorErc20(NETID_TEST, rpcParams, "0xa840d94b1ef4c326c370e84d108d539d31d52e84")
ada := NewAdaptorErc20(NETID_TEST, rpcParams)//"0xa840d94b1ef4c326c370e84d108d539d31d52e84"

addrETH := &adaptor.GetPalletOneMappingAddressInput{ChainAddress: "0x7D7116A8706Ae08bAA7F4909e26728fa7A5f0365"}
addrETH := &adaptor.GetPalletOneMappingAddressInput{
ChainAddress: "0x7D7116A8706Ae08bAA7F4909e26728fa7A5f0365",
MappingDataSource:"0xa840d94b1ef4c326c370e84d108d539d31d52e84"}
outputPTN, err := ada.GetPalletOneMappingAddress(addrETH)
assert.Nil(t, err)
t.Logf("Map PalletOne Address:%s", outputPTN.PalletOneAddress)

addrPTNHex := &adaptor.GetPalletOneMappingAddressInput{PalletOneAddress: "P124gB1bXHDTXmox58g4hd4u13HV3e5vKie"}
addrPTNHex := &adaptor.GetPalletOneMappingAddressInput{
PalletOneAddress: "P124gB1bXHDTXmox58g4hd4u13HV3e5vKie",
MappingDataSource:"0xa840d94b1ef4c326c370e84d108d539d31d52e84"}
outputETH, err := ada.GetPalletOneMappingAddress(addrPTNHex)
assert.Nil(t, err)
t.Logf("Map Chain Address:%s", outputETH.ChainAddress)
Expand Down
24 changes: 16 additions & 8 deletions Application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,24 @@ var (

func TestDepositETH(t *testing.T) {
var aeth adaptor.ICryptoCurrency = NewAdaptorETHTestnet()
multiSignAddr:="0x4d736ed88459b2db85472aab13a9d0ce2a6ea676"
input := &adaptor.CreateMultiSigAddressInput{}
input.Keys = make([][]byte, 4)
input.Keys[0] = j1pubKey
input.Keys[1] = j2pubKey
input.Keys[2] = j3pubKey
input.Keys[3] = j4pubKey
input.SignCount = 3
output, err := aeth.CreateMultiSigAddress(input)
_, err := aeth.CreateMultiSigAddress(input)
t.Logf("Jury pub keys:%x", input.Keys)
t.Logf("Jury addresss:%s", [...]string{j1Addr, j2Addr, j3Addr, j4Addr})
assert.Nil(t, err)
multiSignAddr := output.Address
assert.NotNil(t, err)

t.Logf("MutiSign Address:%s", multiSignAddr)
addrOut, err := aeth.GetPalletOneMappingAddress(&adaptor.GetPalletOneMappingAddressInput{ChainAddress: u1EthAddr})
addrOut, err := aeth.GetPalletOneMappingAddress(
&adaptor.GetPalletOneMappingAddressInput{
ChainAddress: u1EthAddr,
MappingDataSource:multiSignAddr})
assert.Nil(t, err)
t.Logf("PalletOne Address:%s,%x", addrOut.PalletOneAddress, []byte(addrOut.PalletOneAddress))
//User1通过自己的ETH钱包转账到多签地址
Expand All @@ -57,20 +61,24 @@ func TestDepositETH(t *testing.T) {
func TestDepositErc20(t *testing.T) {
var aeth adaptor.ICryptoCurrency = NewAdaptorErc20Testnet()
erc20Asset := "0xa54880da9a63cdd2ddacf25af68daf31a1bcc0c9"
multiSignAddr:="0x4d736ed88459b2db85472aab13a9d0ce2a6ea676"
input := &adaptor.CreateMultiSigAddressInput{}
input.Keys = make([][]byte, 4)
input.Keys[0] = j1pubKey
input.Keys[1] = j2pubKey
input.Keys[2] = j3pubKey
input.Keys[3] = j4pubKey
input.SignCount = 3
output, err := aeth.CreateMultiSigAddress(input)
_, err := aeth.CreateMultiSigAddress(input)
t.Logf("Jury pub keys:%x", input.Keys)
t.Logf("Jury addresss:%s", [...]string{j1Addr, j2Addr, j3Addr, j4Addr})
assert.Nil(t, err)
multiSignAddr := output.Address
assert.NotNil(t, err)
//multiSignAddr := output.Address
t.Logf("MutiSign Address:%s", multiSignAddr)
addrOut, err := aeth.GetPalletOneMappingAddress(&adaptor.GetPalletOneMappingAddressInput{ChainAddress: u1EthAddr})
addrOut, err := aeth.GetPalletOneMappingAddress(
&adaptor.GetPalletOneMappingAddressInput{
ChainAddress: u1EthAddr,
MappingDataSource:multiSignAddr})
assert.Nil(t, err)
t.Logf("PalletOne Address:%s,%x", addrOut.PalletOneAddress, []byte(addrOut.PalletOneAddress))
//User1通过自己的ETH钱包转账到多签地址
Expand Down
12 changes: 12 additions & 0 deletions vendor/github.com/palletone/adaptor/.drone.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/github.com/palletone/adaptor/.golangci.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 0 additions & 22 deletions vendor/github.com/palletone/adaptor/.travis.yml

This file was deleted.

8 changes: 4 additions & 4 deletions vendor/github.com/palletone/adaptor/BlockInfo.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions vendor/github.com/palletone/adaptor/IUtility.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0daa72d

Please sign in to comment.