Skip to content

Commit 9281f0e

Browse files
Merge branch 'develop' into feature/wait-blocks-confirm
2 parents b826e67 + 554bf56 commit 9281f0e

File tree

90 files changed

+9027
-123381
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+9027
-123381
lines changed

.github/workflows/integrationtest.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Run integration tests
2+
on: [push]
3+
jobs:
4+
integration-tests:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@v2
8+
- name: Set up linux environment
9+
run: # installs development tools and updates .bash_profile
10+
bash test/integration/setup-linux-environment.sh
11+
- name: Execute integration tests
12+
run: |
13+
source $HOME/.bash_profile
14+
bash test/integration/start-integration-env.sh

.github/workflows/smart-contracts.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Smart Contracts
2+
3+
on:
4+
pull_request:
5+
paths: ['smart-contracts/**']
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
defaults:
11+
run:
12+
working-directory: smart-contracts
13+
14+
steps:
15+
- name: Check out code
16+
uses: actions/checkout@v2
17+
- name: Use Node.js
18+
uses: actions/setup-node@v2.1.2
19+
with:
20+
node-version: '14.x'
21+
22+
- name: Install dependencies
23+
run: npm install
24+
env:
25+
CI: true
26+
27+
- name: Install truffle
28+
run: npm i -g truffle
29+
30+
- name: Test Setup
31+
run: npm run test:setup
32+
33+
- name: Run truffle tests
34+
run: npm run test

cmd/ebrelayer/txs/parser.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func EthereumEventToEthBridgeClaim(valAddr sdk.ValAddress, event *types.Ethereum
6363
symbol = strings.Join(res[1:], "")
6464
}
6565

66-
amount := event.Value.Int64()
66+
amount := sdk.NewIntFromBigInt(event.Value)
6767

6868
// Nonce type casting (*big.Int -> int)
6969
nonce := int(event.Nonce.Int64())
@@ -133,7 +133,7 @@ func BurnLockEventToCosmosMsg(claimType types.Event, attributes []tmKv.Pair) (ty
133133
var cosmosSenderSequence *big.Int
134134
var ethereumReceiver common.Address
135135
var symbol string
136-
var amount *big.Int
136+
var amount sdk.Int
137137

138138
for _, attribute := range attributes {
139139
key := string(attribute.GetKey())
@@ -169,8 +169,7 @@ func BurnLockEventToCosmosMsg(claimType types.Event, attributes []tmKv.Pair) (ty
169169
symbol = strings.ToUpper(val)
170170
}
171171
case types.Amount.String():
172-
tempAmount := new(big.Int)
173-
tempAmount, ok := tempAmount.SetString(val, 10)
172+
tempAmount, ok := sdk.NewIntFromString(val)
174173
if !ok {
175174
log.Println("Invalid amount:", val)
176175
return types.CosmosMsg{}, errors.New("invalid amount:" + val)

cmd/ebrelayer/txs/parser_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestLogLockToEthBridgeClaim(t *testing.T) {
3131
// Set up expected EthBridgeClaim
3232
expectedEthBridgeClaim := ethbridge.NewEthBridgeClaim(
3333
TestEthereumChainID, testBridgeContractAddress, TestNonce, strings.ToLower(TestSymbol), testTokenContractAddress,
34-
testEthereumAddress, testCosmosAddress, testCosmosValidatorBech32Address, TestAmount, TestLockClaimType)
34+
testEthereumAddress, testCosmosAddress, testCosmosValidatorBech32Address, testSDKAmount, TestLockClaimType)
3535

3636
// Create test ethereum event
3737
ethereumEvent := CreateTestLogEthereumEvent(t)
@@ -111,10 +111,10 @@ func TestMsgBurnToProphecyClaim(t *testing.T) {
111111
expectedProphecyClaim := ProphecyClaim{
112112
ClaimType: types.MsgBurn,
113113
CosmosSender: []byte(TestCosmosAddress1),
114-
CosmosSenderSequence: big.NewInt(int64(TestCosmosAddressSequence)),
114+
CosmosSenderSequence: big.NewInt(1),
115115
EthereumReceiver: common.HexToAddress(TestEthereumAddress1),
116116
Symbol: symbol,
117-
Amount: big.NewInt(int64(TestAmount)),
117+
Amount: testSDKAmount,
118118
}
119119

120120
// Create a MsgBurn as input parameter
@@ -129,10 +129,10 @@ func TestMsgLockToProphecyClaim(t *testing.T) {
129129
expectedProphecyClaim := ProphecyClaim{
130130
ClaimType: types.MsgLock,
131131
CosmosSender: []byte(TestCosmosAddress1),
132-
CosmosSenderSequence: big.NewInt(int64(TestCosmosAddressSequence)),
132+
CosmosSenderSequence: big.NewInt(1),
133133
EthereumReceiver: common.HexToAddress(TestEthereumAddress1),
134134
Symbol: TestSymbol,
135-
Amount: big.NewInt(int64(TestAmount)),
135+
Amount: testSDKAmount,
136136
}
137137

138138
// Create a MsgLock as input parameter

cmd/ebrelayer/txs/relayToEthereum.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func RelayProphecyClaimToEthereum(provider string, contractAddress common.Addres
4242
// Send transaction
4343
fmt.Println("Sending new ProphecyClaim to CosmosBridge...")
4444
tx, err := cosmosBridgeInstance.NewProphecyClaim(auth, uint8(claim.ClaimType),
45-
claim.CosmosSender, claim.CosmosSenderSequence, claim.EthereumReceiver, claim.Symbol, claim.Amount)
45+
claim.CosmosSender, claim.CosmosSenderSequence, claim.EthereumReceiver, claim.Symbol, claim.Amount.BigInt())
4646
if err != nil {
4747
log.Println(err)
4848
return err

cmd/ebrelayer/txs/test_common.go

+10-7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"strings"
88
"testing"
99

10+
sdk "github.com/cosmos/cosmos-sdk/types"
1011
"github.com/ethereum/go-ethereum/common"
1112
tmKv "github.com/tendermint/tendermint/libs/kv"
1213

@@ -25,20 +26,22 @@ const (
2526
TestNonce = 19
2627
TestEthTokenAddress = "0x0000000000000000000000000000000000000000"
2728
TestSymbol = "CETH"
28-
TestAmount = 5
2929
TestEthereumAddress1 = "0x7B95B6EC7EbD73572298cEf32Bb54FA408207359"
3030
TestEthereumAddress2 = "0xc230f38FF05860753840e0d7cbC66128ad308B67"
3131
TestCosmosAddress1 = "cosmos1gn8409qq9hnrxde37kuxwx5hrxpfpv8426szuv"
3232
TestCosmosAddress2 = "cosmos1l5h2x255pvdy9l4z0hf9tr8zw7k657s97wyz7y"
33+
TestExpectedMessage = "8d46d2f689aa50a0dde8563f4ab1c90f4f74a80817ad18052ef1aa8bd5a0fd96"
3334
TestCosmosAddressSequence = 1
34-
TestExpectedMessage = "d39d3a837b322ea6355a4de856bb88e0a1a33a1a9655767df2fa947f42ebcda6"
3535
TestExpectedSignature = "f3b43b87b8b3729d6b380a640954d14e425acd603bc98f5da8437cba9e492e7805c437f977900cf9cfbeb9e0e2e6fc5b189723b0979efff1fc2796a2daf4fd3a01" //nolint:lll
3636
TestAddrHex = "970e8128ab834e8eac17ab8e3812f010678cf791"
3737
TestPrivHex = "289c2857d4598e37fb9647507e47a309d6133539bf21a8b9cb6df88fd5232032"
3838
TestNullAddress = "0x0000000000000000000000000000000000000000"
3939
TestOtherAddress = "0x1000000000000000000000000000000000000000"
4040
)
4141

42+
var testAmount = big.NewInt(5)
43+
var testSDKAmount = sdk.NewIntFromBigInt(testAmount)
44+
4245
// CreateTestLogEthereumEvent creates a sample EthereumEvent event for testing purposes
4346
func CreateTestLogEthereumEvent(t *testing.T) types.EthereumEvent {
4447
testEthereumChainID := big.NewInt(int64(TestEthereumChainID))
@@ -52,7 +55,7 @@ func CreateTestLogEthereumEvent(t *testing.T) types.EthereumEvent {
5255
testEthereumSender := common.HexToAddress(TestEthereumAddress1)
5356
testCosmosRecipient := []byte(TestCosmosAddress1)
5457
testTokenAddress := common.HexToAddress(TestEthTokenAddress)
55-
testAmount := big.NewInt(int64(TestAmount))
58+
testAmount := testAmount
5659
testNonce := big.NewInt(int64(TestNonce))
5760

5861
return types.EthereumEvent{EthereumChainID: testEthereumChainID,
@@ -69,7 +72,7 @@ func CreateTestProphecyClaimEvent(t *testing.T) types.ProphecyClaimEvent {
6972
testEthereumReceiver := common.HexToAddress(TestEthereumAddress1)
7073
testValidatorAddress := common.HexToAddress(TestEthereumAddress2)
7174
testTokenAddress := common.HexToAddress(TestEthTokenAddress)
72-
testAmount := big.NewInt(int64(TestAmount))
75+
testAmount := testSDKAmount
7376

7477
return types.NewProphecyClaimEvent([]byte(TestCosmosAddress1), TestSymbol,
7578
testProphecyID, testAmount, testEthereumReceiver, testValidatorAddress,
@@ -80,7 +83,7 @@ func CreateTestProphecyClaimEvent(t *testing.T) types.ProphecyClaimEvent {
8083
func CreateTestCosmosMsg(t *testing.T, claimType types.Event) types.CosmosMsg {
8184
testCosmosSender := []byte(TestCosmosAddress1)
8285
testEthereumReceiver := common.HexToAddress(TestEthereumAddress1)
83-
testAmount := big.NewInt(int64(TestAmount))
86+
testAmount := testSDKAmount
8487

8588
var symbol string
8689
if claimType == types.MsgBurn {
@@ -91,7 +94,7 @@ func CreateTestCosmosMsg(t *testing.T, claimType types.Event) types.CosmosMsg {
9194
}
9295

9396
// Create new Cosmos Msg
94-
cosmosMsg := types.NewCosmosMsg(claimType, testCosmosSender, big.NewInt(int64(TestCosmosAddressSequence)),
97+
cosmosMsg := types.NewCosmosMsg(claimType, testCosmosSender, big.NewInt(TestCosmosAddressSequence),
9598
testEthereumReceiver, symbol, testAmount)
9699

97100
return cosmosMsg
@@ -134,7 +137,7 @@ func CreateCosmosMsgAttributes(t *testing.T, claimType types.Event) []tmKv.Pair
134137
// (key, value) pairing for "amount" key
135138
pairAmount := tmKv.Pair{
136139
Key: []byte("amount"),
137-
Value: []byte(strconv.Itoa(TestAmount)),
140+
Value: []byte(testAmount.String()),
138141
}
139142

140143
// (key, value) pairing for "token_contract_address" key

cmd/ebrelayer/txs/types.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"math/big"
55

66
"github.com/Sifchain/sifnode/cmd/ebrelayer/types"
7+
sdk "github.com/cosmos/cosmos-sdk/types"
78
"github.com/ethereum/go-ethereum/common"
89
)
910

@@ -17,9 +18,9 @@ type OracleClaim struct {
1718
// ProphecyClaim contains data required to make an ProphecyClaim
1819
type ProphecyClaim struct {
1920
CosmosSender []byte
20-
CosmosSenderSequence *big.Int
2121
Symbol string
22-
Amount *big.Int
22+
Amount sdk.Int
2323
EthereumReceiver common.Address
2424
ClaimType types.Event
25+
CosmosSenderSequence *big.Int
2526
}

cmd/ebrelayer/types/types.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/ethereum/go-ethereum/common"
99

1010
ethbridge "github.com/Sifchain/sifnode/x/ethbridge/types"
11+
sdk "github.com/cosmos/cosmos-sdk/types"
1112
)
1213

1314
// Event enum containing supported chain events
@@ -73,15 +74,15 @@ type ProphecyClaimEvent struct {
7374
CosmosSender []byte
7475
Symbol string
7576
ProphecyID *big.Int
76-
Amount *big.Int
77+
Amount sdk.Int
7778
EthereumReceiver common.Address
7879
ValidatorAddress common.Address
7980
TokenAddress common.Address
8081
ClaimType uint8
8182
}
8283

8384
// NewProphecyClaimEvent creates a new ProphecyClaimEvent
84-
func NewProphecyClaimEvent(cosmosSender []byte, symbol string, prophecyID, amount *big.Int, ethereumReceiver,
85+
func NewProphecyClaimEvent(cosmosSender []byte, symbol string, prophecyID *big.Int, amount sdk.Int, ethereumReceiver,
8586
validatorAddress, tokenAddress common.Address, claimType uint8) ProphecyClaimEvent {
8687
return ProphecyClaimEvent{
8788
CosmosSender: cosmosSender,
@@ -108,14 +109,14 @@ type CosmosMsg struct {
108109
CosmosSender []byte
109110
CosmosSenderSequence *big.Int
110111
Symbol string
111-
Amount *big.Int
112+
Amount sdk.Int
112113
EthereumReceiver common.Address
113114
ClaimType Event
114115
}
115116

116117
// NewCosmosMsg creates a new CosmosMsg
117118
func NewCosmosMsg(claimType Event, cosmosSender []byte, cosmosSenderSequence *big.Int, ethereumReceiver common.Address, symbol string,
118-
amount *big.Int) CosmosMsg {
119+
amount sdk.Int) CosmosMsg {
119120
return CosmosMsg{
120121
ClaimType: claimType,
121122
CosmosSender: cosmosSender,

deploy/rake/genesis.rake

+15-11
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ namespace :genesis do
3838
puts "the file #{network_config(args[:chainnet])} does not exist!"
3939
exit(1)
4040
end
41-
42-
build_docker_image(args[:chainnet])
41+
if args[:chainnet] != 'localnet'
42+
build_docker_image(args[:chainnet])
43+
end
4344
boot_docker_network(chainnet: args[:chainnet], seed_network_address: "192.168.2.0/24", eth_config: with_eth)
4445
end
4546

@@ -50,25 +51,25 @@ namespace :genesis do
5051

5152
desc "Reset the state of a network"
5253
task :reset, [:chainnet] do |t, args|
53-
system("sifgen network reset #{args[:chainnet]} #{cwd}/../networks")
54+
safe_system("sifgen network reset #{args[:chainnet]} #{cwd}/../networks")
5455
end
5556
end
5657

5758
desc "node operations"
5859
namespace :sifnode do
5960
desc "Scaffold a new local node and configure it to connect to an existing network"
6061
task :scaffold, [:chainnet, :peer_address, :genesis_url] do |t, args|
61-
system("sifgen node create #{args[:chainnet]} #{args[:peer_address]} #{args[:genesis_url]}")
62+
safe_system("sifgen node create #{args[:chainnet]} #{args[:peer_address]} #{args[:genesis_url]}")
6263
end
6364

6465
desc "boot scaffolded node and connect to existing network"
6566
task :boot do
66-
system("sifnoded start --p2p.laddr tcp://0.0.0.0:26658 ")
67+
safe_system("sifnoded start --p2p.laddr tcp://0.0.0.0:26658 ")
6768
end
6869

6970
desc "Reset the state of a node"
7071
task :reset, [:chainnet, :node_directory] do |t, args|
71-
system("sifgen node reset #{args[:chainnet]} #{args[:node_directory]}")
72+
safe_system("sifgen node reset #{args[:chainnet]} #{args[:node_directory]}")
7273
end
7374
end
7475
end
@@ -83,7 +84,7 @@ end
8384
# @param network_config Name of the file to use to output the config to
8485
#
8586
def network_create(chainnet:, validator_count:, build_dir:, seed_ip_address:, network_config:)
86-
system("sifgen network create #{chainnet} #{validator_count} #{build_dir} #{seed_ip_address} #{network_config}")
87+
safe_system("sifgen network create #{chainnet} #{validator_count} #{build_dir} #{seed_ip_address} #{network_config}")
8788
end
8889

8990
#
@@ -101,9 +102,12 @@ def boot_docker_network(chainnet:, seed_network_address:, eth_config:)
101102
network.each_with_index do |node, idx|
102103
cmd += "MONIKER#{idx+1}=#{node['moniker']} MNEMONIC#{idx+1}=\"#{node['mnemonic']}\" IPV4_ADDRESS#{idx+1}=#{node['ipv4_address']} "
103104
end
104-
105-
cmd += "IPV4_SUBNET=#{seed_network_address} #{eth_config} docker-compose -f #{cwd}/../genesis/docker-compose.yml up #{instances} | tee #{cwd}/../../log/#{chainnet}.log"
106-
system(cmd)
105+
if chainnet == 'localnet'
106+
cmd += "IPV4_SUBNET=#{seed_network_address} #{eth_config} docker-compose -f #{cwd}/../../test/integration/docker-compose-integration.yml up -d | tee #{cwd}/../../log/#{chainnet}.log"
107+
else
108+
cmd += "IPV4_SUBNET=#{seed_network_address} #{eth_config} docker-compose -f #{cwd}/../genesis/docker-compose.yml up #{instances} | tee #{cwd}/../../log/#{chainnet}.log"
109+
end
110+
safe_system(cmd)
107111
end
108112

109113
#
@@ -112,7 +116,7 @@ end
112116
# @param chainnet Name or ID of the chain
113117
#
114118
def build_docker_image(chainnet)
115-
system("docker build -f #{cwd}/../genesis/Dockerfile -t sifchain/sifnoded:#{chainnet} #{cwd}/../../")
119+
safe_system("docker build -f #{cwd}/../genesis/Dockerfile -t sifchain/sifnoded:#{chainnet} #{cwd}/../../")
116120
end
117121

118122
#

deploy/rake/helpers.rake

+11-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ end
3939
# @params chainnet Name or ID of the chain
4040
#
4141
def network_config(chainnet)
42-
"#{cwd}/../networks/#{Digest::SHA256.hexdigest chainnet}.yml"
42+
if chainnet == 'localnet'
43+
"#{cwd}/../networks/network-definition.yml"
44+
else
45+
"#{cwd}/../networks/#{Digest::SHA256.hexdigest chainnet}.yml"
46+
end
4347
end
4448

4549
#
@@ -79,3 +83,9 @@ def detect_os
7983
end
8084
)
8185
end
86+
87+
def safe_system(cmd)
88+
if (!system(cmd))
89+
STDERR.puts("System cmd failed: #{cmd}")
90+
end
91+
end

docs/4.Running-the-Integration-Test-Suite.md

-4
This file was deleted.

scripts/start-integration-env.sh

-24
This file was deleted.

0 commit comments

Comments
 (0)