Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ name: Go

on:
push:
branches: [ "main", "devnet", "testnet"]
branches: ["main", "devnet", "testnet"]
pull_request:
branches: [ "main", "devnet", "testnet" ]
branches: ["main", "devnet", "testnet"]

jobs:

TestAndBuild:
runs-on: ubuntu-latest
env:
WalletSdkTestM1: ${{ secrets.WALLETSDKTESTM1 }}
integration-test:
runs-on: ubuntu-22.04-arm
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.24.3

- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19
- name: Start Sui
run: docker compose up -d --quiet-pull

- name: Test
run: go test -v ./...
- name: Integration Test
run: go test -v ./...

- name: Build
run: go build -v ./...
- name: Build
run: go build -v ./...
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# go-sui-sdk
Sui Golang SDK
Sui Golang SDK forked from [coming-chat/go-sui-sdk](https://github.com/coming-chat/go-sui-sdk)

[![Documentation (master)](https://img.shields.io/badge/docs-master-59f)](https://github.com/coming-chat/go-sui-sdk)
[![License](https://img.shields.io/badge/license-Apache-green.svg)](https://github.com/coming-chat/go-sui-sdk/blob/main/LICENSE)
[![Documentation (master)](https://img.shields.io/badge/docs-master-59f)](https://github.com/stork-oracle/go-sui-sdk)
[![License](https://img.shields.io/badge/license-Apache-green.svg)](https://github.com/stork-oracle/go-sui-sdk/blob/main/LICENSE)

The Sui Golang SDK for ComingChat.
The Sui Golang SDK for Stork Oracle.
We welcome other developers to participate in the development and testing of sui-sdk.

## Install

```sh
go get github.com/coming-chat/go-sui/v2
go get github.com/stork-oracle/go-sui-sdk
```


Expand All @@ -20,7 +20,7 @@ go get github.com/coming-chat/go-sui/v2
### Account

```go
import "github.com/coming-chat/go-sui/account"
import "github.com/stork-oracle/go-sui/account"

// Import account with mnemonic
acc, err := account.NewAccountWithMnemonic(mnemonic)
Expand All @@ -45,8 +45,8 @@ signedData := acc.Sign(data)
All data interactions on the Sui chain are implemented through the rpc client.

```go
import "github.com/coming-chat/go-sui/client"
import "github.com/coming-chat/go-sui/types"
import "github.com/stork-oracle/go-sui/client"
import "github.com/stork-oracle/go-sui/types"

cli, err := client.Dial(rpcUrl)

Expand All @@ -69,16 +69,16 @@ print("transaction timestamp = ", resp.TimestampMs)

```

We currently have some rpc methods built-in, [see here](https://github.com/coming-chat/go-sui-sdk/blob/main/client/client_call.go)
We currently have some rpc methods built-in, [see here](https://github.com/stork-oracle/go-sui-sdk/blob/main/client/client_call.go)



### Build Transaction & Sign ( Transfer Sui )

```go
import "github.com/coming-chat/go-sui/client"
import "github.com/coming-chat/go-sui/types"
import "github.com/coming-chat/go-sui/account"
import "github.com/stork-oracle/go-sui/client"
import "github.com/stork-oracle/go-sui/types"
import "github.com/stork-oracle/go-sui/account"

acc, err := account.NewAccountWithMnemonic(mnemonic)
signer, _ := types.NewAddressFromHex(acc.Address)
Expand Down
4 changes: 2 additions & 2 deletions account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"encoding/hex"

"github.com/coming-chat/go-aptos/crypto/derivation"
"github.com/coming-chat/go-sui/v2/sui_types"
"github.com/tyler-smith/go-bip39"
"github.com/cosmos/go-bip39"
"github.com/stork-oracle/go-sui-sdk/sui_types"
"golang.org/x/crypto/blake2b"
)

Expand Down
7 changes: 4 additions & 3 deletions account/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@ package account

import (
"encoding/json"
"os"
"testing"

"github.com/coming-chat/go-sui/v2/sui_types"
"github.com/stork-oracle/go-sui-sdk/sui_types"
"github.com/stretchr/testify/require"
)

var Mnemonic = os.Getenv("WalletSdkTestM1")
var Mnemonic = "auction dose outer sorry interest daring marine tent element curious warm penalty"

func TestMyAccouunt(t *testing.T) {
t.Parallel()
account, err := NewAccountWithMnemonic(Mnemonic)
require.Nil(t, err)

t.Logf("addr = %v", account.Address)
}

func Test_Signature_Marshal_Unmarshal(t *testing.T) {
t.Parallel()
account, err := NewAccountWithMnemonic(Mnemonic)
require.Nil(t, err)

Expand Down
76 changes: 41 additions & 35 deletions client/0_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,61 @@ package client

import (
"context"
"os"
"strconv"
"testing"

"github.com/coming-chat/go-sui/v2/sui_types"
"github.com/coming-chat/go-sui/v2/types"
"github.com/shopspring/decimal"
"github.com/stork-oracle/go-sui-sdk/sui_types"
"github.com/stork-oracle/go-sui-sdk/types"

"github.com/coming-chat/go-sui/v2/account"
"github.com/stork-oracle/go-sui-sdk/account"
"github.com/stretchr/testify/require"
)

var (
M1Mnemonic = os.Getenv("WalletSdkTestM1")
Address, _ = sui_types.NewAddressFromHex("0x7e875ea78ee09f08d72e2676cf84e0f1c8ac61d94fa339cc8e37cace85bebc6e")
M1Mnemonic = "auction dose outer sorry interest daring marine tent element curious warm penalty"
Address, _ = sui_types.NewAddressFromHex("0xf0ac79b51afa31bf3f6ca6cde5ab78b05b08362a0cfdb2923ae4c48115426589")
)

func MainnetClient(t *testing.T) *Client {
c, err := Dial(types.MainnetRpcUrl)
require.NoError(t, err)
return c
}
// func MainnetClient(t *testing.T) *Client {
// c, err := Dial(types.MainnetRpcUrl)
// require.NoError(t, err)
// return c
// }

func TestnetClient(t *testing.T) *Client {
c, err := Dial(types.TestnetRpcUrl)
require.NoError(t, err)
return c
}
// func TestnetClient(t *testing.T) *Client {
// c, err := Dial(types.TestnetRpcUrl)
// require.NoError(t, err)
// return c
// }

func DevnetClient(t *testing.T) *Client {
c, err := Dial(types.DevNetRpcUrl)
require.NoError(t, err)
// func DevnetClient(t *testing.T) *Client {
// c, err := Dial(types.DevNetRpcUrl)
// require.NoError(t, err)

// balance, err := c.GetBalance(context.Background(), *Address, types.SUI_COIN_TYPE)
// require.NoError(t, err)
// if balance.TotalBalance.BigInt().Uint64() < SUI(0.3).Uint64() {
// _, err = FaucetFundAccount(Address.String(), DevNetFaucetUrl)
// require.NoError(t, err)
// }
// return c
// }

func LocalFundedClient(t *testing.T) *Client {
c, err := Dial("http://localhost:9000")
require.NoError(t, err)
balance, err := c.GetBalance(context.Background(), *Address, types.SUI_COIN_TYPE)
require.NoError(t, err)
if balance.TotalBalance.BigInt().Uint64() < SUI(0.3).Uint64() {
_, err = FaucetFundAccount(Address.String(), DevNetFaucetUrl)
for balance.TotalBalance.BigInt().Uint64() < SUI(0.3).Uint64() {
_, err = FaucetFundAccount(Address.String(), "http://localhost:9123/gas")
require.NoError(t, err)
balance, err = c.GetBalance(context.Background(), *Address, types.SUI_COIN_TYPE)
require.NoError(t, err)
}
return c
}

func ChainClient(t *testing.T) *Client {
suiEnv := os.Getenv("SUI_NETWORK")
switch suiEnv {
case "testnet":
return TestnetClient(t)
case "devnet":
return DevnetClient(t)
case "":
fallthrough
default:
return TestnetClient(t)
}
}

func M1Account(t *testing.T) *account.Account {
a, err := account.NewAccountWithMnemonic(M1Mnemonic)
require.NoError(t, err)
Expand Down Expand Up @@ -91,3 +90,10 @@ func SuiAddressNoErr(str string) *suiAddress {
s, _ := sui_types.NewAddressFromHex(str)
return s
}

func ValidatorAddress(t *testing.T) *suiAddress {
cli := LocalFundedClient(t)
state, err := cli.GetLatestSuiSystemState(context.Background())
require.NoError(t, err)
return &state.ActiveValidators[0].SuiAddress
}
6 changes: 3 additions & 3 deletions client/account_sign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"testing"

"github.com/coming-chat/go-sui/v2/account"
"github.com/coming-chat/go-sui/v2/types"
"github.com/stork-oracle/go-sui-sdk/account"
"github.com/stork-oracle/go-sui-sdk/types"
"github.com/stretchr/testify/require"
)

Expand All @@ -20,7 +20,7 @@ func ManualTest_AccountSignAndSend(t *testing.T) {
require.Nil(t, err)
t.Log(account.Address)

cli := TestnetClient(t)
cli := LocalFundedClient(t)
signer := SuiAddressNoErr(account.Address)
coins, err := cli.GetSuiCoinsOwnedByAddress(context.Background(), *signer)
require.Nil(t, err)
Expand Down
Loading