Skip to content

Commit aa5083f

Browse files
Aseyedvorujack
authored andcommitted
Test
1 parent 3b6572b commit aa5083f

19 files changed

+1015
-254
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
.idea
44
.env
55
gravity-node-data-extractor
6-
config.json
6+
config.json

bsc-testnet_devnet-solana.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"SourceDecimals": 18,
3+
"DestinationDecimals": 8,
4+
"SourceNodeURL": "https://data-seed-prebsc-1-s1.binance.org:8545",
5+
"DestinationNodeURL": "https://api.devnet.solana.com",
6+
"LUPortAddress": "0x10a785aa24d8540C583Ad99Bc82E5d7aF61b5806",
7+
"IBPortAddress": "",
8+
}

config/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type MainConfig struct {
1818
SourceDecimals, DestinationDecimals int64
1919
IBPortAddress string
2020
LUPortAddress string
21+
Meta map[string]string
2122
}
2223

2324
func ParseMainConfig(confName string) (*MainConfig, error) {

erg-erg.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"SourceNodeURL": "http://176.9.65.58:9016/",
3-
"SourceDecimals": 6
4-
"DestinationDecimals": 6,
3+
"SourceDecimals": 9,
4+
"DestinationDecimals": 9,
55
"DestinationNodeURL": "http://176.9.65.58:9016/",
66
"IBPortAddress": "ibport",
77
"LUPortAddress": "luport"

evm_to_solana-cfg.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"SourceDecimals": 18,
3+
"DestinationDecimals": 8,
4+
"SourceNodeURL": "https://data-seed-prebsc-1-s1.binance.org:8545",
5+
"DestinationNodeURL": "https://api.devnet.solana.com",
6+
"LUPortAddress": "0x10a785aa24d8540C583Ad99Bc82E5d7aF61b5806",
7+
"IBPortAddress": "FUBmUQLU1h7EdKEkgfjhR8GozMHxrWYSJNNnAXu7ZidJ"
8+
}

extractors/susy/bridge/common.go

+64-9
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,20 @@ package bridge
22

33
import (
44
"context"
5+
"encoding/base64"
6+
"fmt"
7+
58
"github.com/Gravity-Tech/gravity-node-data-extractor/v2/extractors"
69
"github.com/Gravity-Tech/gravity-node-data-extractor/v2/helpers"
710
"github.com/ethereum/go-ethereum/common"
811
"github.com/mr-tron/base58"
912
wavescrypto "github.com/wavesplatform/go-lib-crypto"
13+
1014
"math/big"
15+
16+
solclient "github.com/portto/solana-go-sdk/client"
17+
solcommon "github.com/portto/solana-go-sdk/common"
18+
soltoken "github.com/portto/solana-go-sdk/tokenprog"
1119
)
1220

1321
/**
@@ -28,7 +36,9 @@ type ConfigureCommand struct {
2836
LUPortAddress, IBPortAddress string
2937
SourceDecimals, DestinationDecimals int64
3038

31-
SourceNodeUrl, DestinationNodeUrl string
39+
SourceNodeUrl, DestinationNodeUrl string
40+
41+
Meta map[string]string
3242
}
3343

3444
type RequestId string
@@ -59,21 +69,20 @@ type Action int
5969
type RequestType int
6070

6171
const (
62-
NewStatus Status = 1
63-
CompletedStatus Status = 2
72+
NewStatus Status = 1
73+
CompletedStatus Status = 2
6474

6575
ApproveAction Action = 1
6676
UnlockAction Action = 2
6777
MintAction Action = 1
6878
ChangeStatusAction Action = 2
6979

70-
IssueType RequestType = 1
71-
BurnType RequestType = 2
72-
LockType RequestType = 1
73-
UnlockType RequestType = 2
80+
IssueType RequestType = 1
81+
BurnType RequestType = 2
82+
LockType RequestType = 1
83+
UnlockType RequestType = 2
7484
)
7585

76-
7786
func ValidateEthereumBasedAddress(address string) bool {
7887
return common.IsHexAddress(address)
7988
}
@@ -83,7 +92,53 @@ func ValidateWavesAddress(address string, chainId byte) bool {
8392
return instance.VerifyAddress(wavescrypto.Address(address), wavescrypto.WavesChainID(chainId))
8493
}
8594

95+
func ValidateSolanaTokenAccountOwnershipByTokenProgram(client *solclient.Client, tokenAccount string, metaData map[string]string) (bool, error) {
96+
ctx, cancel := context.WithCancel(context.Background())
97+
defer cancel()
98+
99+
stateResult, err := client.GetAccountInfo(ctx, tokenAccount, solclient.GetAccountInfoConfig{
100+
Encoding: "base64",
101+
})
102+
if err != nil {
103+
return false, err
104+
}
105+
106+
if stateResult.Owner != solcommon.TokenProgramID.ToBase58() {
107+
return false, fmt.Errorf("owner mismatch - got: %v; expected: %v", stateResult.Owner, solcommon.TokenProgramID.ToBase58())
108+
}
109+
110+
tokenState := stateResult.Data.([]interface{})[0].(string)
111+
tokenStateDecoded, err := base64.StdEncoding.DecodeString(tokenState)
112+
if err != nil {
113+
return false, err
114+
}
115+
116+
tokenAccountState, err := soltoken.TokenAccountFromData(tokenStateDecoded)
117+
if err != nil {
118+
return false, err
119+
}
120+
121+
tokenMint := metaData["token_mint"]
122+
fmt.Printf("tokenMint: %+v \n", tokenMint)
123+
124+
if tokenAccountState.Mint.ToBase58() != tokenMint {
125+
return false, fmt.Errorf("token mint mismatch - got: %v; expected: %v", tokenAccountState.Mint.ToBase58(), tokenMint)
126+
}
127+
128+
fmt.Printf("tokenAccount: %+v \n", tokenAccount)
129+
130+
return true, nil
131+
}
132+
133+
func ValidateSolanaAddress(address string) bool {
134+
_, err := base58.Decode(address)
135+
if err != nil {
136+
return false
137+
}
138+
return true
139+
}
140+
86141
func ValidateErgoAddress(address string) bool {
87-
isValid , _ := helpers.CheckAddress(address)
142+
isValid, _ := helpers.CheckAddress(address)
88143
return isValid
89144
}

extractors/susy/bridge/ergo_test.go

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package bridge
2+
3+
import (
4+
"context"
5+
"github.com/Gravity-Tech/gravity-node-data-extractor/v2/extractors"
6+
"github.com/Gravity-Tech/gravity-node-data-extractor/v2/helpers"
7+
"testing"
8+
)
9+
10+
func TestErgToErgExtractionBridge_Configure(t *testing.T) {
11+
type fields struct {
12+
config ConfigureCommand
13+
configured bool
14+
ergClientSource *helpers.ErgClient
15+
ergClientTarget *helpers.ErgClient
16+
}
17+
type args struct {
18+
config ConfigureCommand
19+
}
20+
tests := []struct {
21+
name string
22+
fields fields
23+
args args
24+
wantErr bool
25+
}{
26+
{name: "already configured", fields: fields{configured: true}, args: args{}, wantErr: true},
27+
}
28+
for _, tt := range tests {
29+
t.Run(tt.name, func(t *testing.T) {
30+
provider := &ErgoToErgoExtractionBridge{
31+
config: tt.fields.config,
32+
configured: tt.fields.configured,
33+
ergClientSource: tt.fields.ergClientSource,
34+
ergClientTarget: tt.fields.ergClientTarget,
35+
}
36+
if err := provider.Configure(tt.args.config); (err != nil) != tt.wantErr {
37+
t.Errorf("ErgoToErgoExtractionBridge.Configure() error = %v, wantErr %v", err, tt.wantErr)
38+
}
39+
})
40+
}
41+
}
42+
43+
func TestErgoToErgoExtractionBridge_ExtractReverseTransferRequest(t *testing.T) {
44+
type fields struct {
45+
config ConfigureCommand
46+
configured bool
47+
ergClientSource *helpers.ErgClient
48+
ergClientTarget *helpers.ErgClient
49+
}
50+
type args struct {
51+
ctx context.Context
52+
}
53+
tests := []struct {
54+
name string
55+
fields fields
56+
args args
57+
want *extractors.Data
58+
wantErr bool
59+
}{
60+
{name: "simple", fields: fields{}, args: args{ctx: context.Background()}, wantErr: false},
61+
}
62+
for _, tt := range tests {
63+
t.Run(tt.name, func(t *testing.T) {
64+
provider := &WavesToEthereumExtractionBridge{}
65+
cmd := ConfigureCommand{
66+
SourceDecimals: 9,
67+
DestinationDecimals: 9,
68+
SourceNodeUrl: "http://176.9.65.58:9016",
69+
DestinationNodeUrl: "http://176.9.65.58:9016",
70+
IBPortAddress: "import",
71+
LUPortAddress: "luport",
72+
}
73+
74+
provider.Configure(cmd)
75+
_, err := provider.ExtractReverseTransferRequest(tt.args.ctx)
76+
if (err != nil) != tt.wantErr {
77+
t.Errorf("ErgoToErgoExtractionBridge.ExtractReverseTransferRequest() error = %v, wantErr %v", err, tt.wantErr)
78+
return
79+
}
80+
})
81+
}
82+
}
83+
84+
func TestErgoToErgoExtractionBridge_ExtractDirectTransferRequest(t *testing.T) {
85+
type fields struct {
86+
config ConfigureCommand
87+
configured bool
88+
ergClientSource *helpers.ErgClient
89+
ergClientTarget *helpers.ErgClient
90+
}
91+
type args struct {
92+
ctx context.Context
93+
}
94+
tests := []struct {
95+
name string
96+
fields fields
97+
args args
98+
want *extractors.Data
99+
wantErr bool
100+
}{
101+
{name: "simple", fields: fields{}, args: args{ctx: context.Background()}, wantErr: false},
102+
}
103+
for _, tt := range tests {
104+
t.Run(tt.name, func(t *testing.T) {
105+
provider := &WavesToEthereumExtractionBridge{}
106+
cmd := ConfigureCommand{
107+
SourceDecimals: 9,
108+
DestinationDecimals: 9,
109+
SourceNodeUrl: "http://176.9.65.58:9016",
110+
DestinationNodeUrl: "http://176.9.65.58:9016",
111+
IBPortAddress: "import",
112+
LUPortAddress: "luport",
113+
}
114+
115+
provider.Configure(cmd)
116+
_, err := provider.ExtractDirectTransferRequest(tt.args.ctx)
117+
if (err != nil) != tt.wantErr {
118+
t.Errorf("ErgoToErgoExtractionBridge.ExtractDirectTransferRequest() error = %v, wantErr %v", err, tt.wantErr)
119+
return
120+
}
121+
})
122+
}
123+
}

extractors/susy/bridge/evm.go

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package bridge
2+
3+
4+
func BuildForEVMByteArray(action uint8, rqIDBytes [32]byte, amountBytes [32]byte, evmReceiver [20]byte) []byte {
5+
result := []byte{action}
6+
result = append(result, rqIDBytes[:]...)
7+
result = append(result, amountBytes[:]...)
8+
result = append(result, evmReceiver[0:20]...)
9+
10+
return result
11+
}

0 commit comments

Comments
 (0)