-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
352fbc6
commit 37bbc5e
Showing
18 changed files
with
405 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package e2e | ||
|
||
import ( | ||
"github.com/ethereum/go-ethereum/common/hexutil" | ||
"github.com/vechain/thor/v2/tests/e2e/client" | ||
"github.com/vechain/thor/v2/tests/e2e/network" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestAccountBalance(t *testing.T) { | ||
network.StartCompose(t) | ||
|
||
account, err := client.Default.GetAccount("0xf077b491b355E64048cE21E3A6Fc4751eEeA77fa") | ||
|
||
assert.NoError(t, err, "GetAccount()") | ||
|
||
balance, err := account.Balance.MarshalText() | ||
|
||
assert.NoError(t, err, "MarshalText()") | ||
|
||
assert.Equal(t, hexutil.Encode(balance), "0x307831346164663462373332303333346239303030303030") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package e2e | ||
|
||
import ( | ||
"github.com/vechain/thor/v2/tests/e2e/client" | ||
"github.com/vechain/thor/v2/tests/e2e/network" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetBlock(t *testing.T) { | ||
network.StartCompose(t) | ||
|
||
block, err := client.Default.GetCompressedBlock(1) | ||
|
||
assert.NoError(t, err, "GetCompressedBlock()") | ||
assert.Greater(t, block.Number, uint32(0), "GetCompressedBlock()") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package client | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/vechain/thor/v2/api/accounts" | ||
"github.com/vechain/thor/v2/api/blocks" | ||
"net/http" | ||
"strconv" | ||
) | ||
|
||
var ( | ||
Default = NewThorClient("http://localhost:8669") | ||
Node1 = NewThorClient("http://localhost:8669") | ||
Node2 = NewThorClient("http://localhost:8679") | ||
Node3 = NewThorClient("http://localhost:8689") | ||
) | ||
|
||
type ThorClient struct { | ||
baseUrl string | ||
} | ||
|
||
func NewThorClient(baseUrl string) *ThorClient { | ||
return &ThorClient{baseUrl: baseUrl} | ||
} | ||
|
||
func (c *ThorClient) GetAccount(address string) (*accounts.Account, error) { | ||
return Get(c, "/accounts/"+address, new(accounts.Account)) | ||
} | ||
|
||
func (c *ThorClient) GetExpandedBlock(number int32) (*blocks.JSONExpandedBlock, error) { | ||
return Get(c, "/blocks/"+strconv.Itoa(int(number))+"?expanded=true", new(blocks.JSONExpandedBlock)) | ||
} | ||
|
||
func (c *ThorClient) GetCompressedBlock(number int32) (*blocks.JSONCollapsedBlock, error) { | ||
return Get(c, "/blocks/"+strconv.Itoa(int(number)), new(blocks.JSONCollapsedBlock)) | ||
} | ||
|
||
func Get[T any](c *ThorClient, endpoint string, v *T) (*T, error) { | ||
|
||
resp, err := http.Get(c.baseUrl + endpoint) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
defer resp.Body.Close() | ||
|
||
err = json.NewDecoder(resp.Body).Decode(v) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return v, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
{ | ||
"launchTime": 1703180212, | ||
"gasLimit": 10000000, | ||
"extraData": "My custom VeChain", | ||
"accounts": [ | ||
{ | ||
"address": "0x7567d83b7b8d80addcb281a71d54fc7b3364ffed", | ||
"balance": "0x14ADF4B7320334B9000000", | ||
"energy": 0, | ||
"code": "0x6060604052600256", | ||
"storage": { | ||
"0x0000000000000000000000000000000000000000000000000000000000000001": "0x0000000000000000000000000000000000000000000000000000000000000002" | ||
} | ||
}, | ||
{ | ||
"address": "0xf077b491b355e64048ce21e3a6fc4751eeea77fa", | ||
"balance": "0x14ADF4B7320334B9000000", | ||
"energy": "0x14ADF4B7320334B9000000" | ||
}, | ||
{ | ||
"address": "0x435933c8064b4ae76be665428e0307ef2ccfbd68", | ||
"balance": "0x14ADF4B7320334B9000000", | ||
"energy": "0x14ADF4B7320334B9000000" | ||
}, | ||
{ | ||
"address": "0x0f872421dc479f3c11edd89512731814d0598db5", | ||
"balance": "0x14ADF4B7320334B9000000", | ||
"energy": "0x14ADF4B7320334B9000000" | ||
}, | ||
{ | ||
"address": "0xf370940abdbd2583bc80bfc19d19bc216c88ccf0", | ||
"balance": "0x14ADF4B7320334B9000000", | ||
"energy": "0x14ADF4B7320334B9000000" | ||
}, | ||
{ | ||
"address": "0x99602e4bbc0503b8ff4432bb1857f916c3653b85", | ||
"balance": "0x14ADF4B7320334B9000000", | ||
"energy": "0x14ADF4B7320334B9000000" | ||
}, | ||
{ | ||
"address": "0x61e7d0c2b25706be3485980f39a3a994a8207acf", | ||
"balance": "0x14ADF4B7320334B9000000", | ||
"energy": "0x14ADF4B7320334B9000000" | ||
}, | ||
{ | ||
"address": "0x361277d1b27504f36a3b33d3a52d1f8270331b8c", | ||
"balance": "0x14ADF4B7320334B9000000", | ||
"energy": "0x14ADF4B7320334B9000000" | ||
}, | ||
{ | ||
"address": "0xd7f75a0a1287ab2916848909c8531a0ea9412800", | ||
"balance": "0x14ADF4B7320334B9000000", | ||
"energy": "0x14ADF4B7320334B9000000" | ||
} | ||
], | ||
"authority": [ | ||
{ | ||
"masterAddress": "0x435933c8064b4ae76be665428e0307ef2ccfbd68", | ||
"endorsorAddress": "0x7567d83b7b8d80addcb281a71d54fc7b3364ffed", | ||
"identity": "0x000000000000000068747470733a2f2f636f6e6e65782e76656368612e696e2f" | ||
}, | ||
{ | ||
"masterAddress": "0xf370940abdbd2583bc80bfc19d19bc216c88ccf0", | ||
"endorsorAddress": "0x7567d83b7b8d80addcb281a71d54fc7b3364ffed", | ||
"identity": "0x000000000000000068747470733a2f2f656e762e7665636861696e2e6f72672f" | ||
}, | ||
{ | ||
"masterAddress": "0x0f872421dc479f3c11edd89512731814d0598db5", | ||
"endorsorAddress": "0x7567d83b7b8d80addcb281a71d54fc7b3364ffed", | ||
"identity": "0x0000000000000068747470733a2f2f617070732e7665636861696e2e6f72672f" | ||
} | ||
], | ||
"params": { | ||
"rewardRatio": 300000000000000000, | ||
"baseGasPrice": 1000000000000000, | ||
"proposerEndorsement": "0x14ADF4B7320334B9000000", | ||
"executorAddress": "0x0000000000000000000000004578656375746f72" | ||
}, | ||
"executor": { | ||
"approvers": [ | ||
{ | ||
"address": "0x199b836d8a57365baccd4f371c1fabb7be77d389", | ||
"identity": "0x00000000000067656e6572616c20707572706f736520626c6f636b636861696e" | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/sh | ||
|
||
# Set the URL | ||
url="http://localhost:8669/blocks/best" | ||
|
||
# Make the HTTP request and store the response in a variable | ||
response=$(wget -qO- $url) | ||
|
||
echo $response | ||
|
||
# Extract the value of "number" from the JSON response using grep | ||
number=$(echo $response | grep -o '"number":[^,}]*' | awk -F: '{print $2}' | tr -d '[:space:]') | ||
|
||
# Check if the number is greater than 0 | ||
if [ $number -gt 0 ]; then | ||
echo "Health check passed! Number is greater than 0." | ||
exit 0 | ||
else | ||
echo "Health check failed! Unexpected response or number is not greater than 0:" | ||
echo $response | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/sh | ||
|
||
if [[ -n $MASTER_KEY_ADDRESS ]]; then | ||
echo "Starting node with master key address $MASTER_KEY_ADDRESS" | ||
|
||
cp /node/keys/$MASTER_KEY_ADDRESS/master.key /tmp | ||
fi | ||
|
||
BOOTNODE_IP=$(ping -c 1 thor-disco | awk -F'[()]' '/PING/{print $2}') | ||
echo $BOOTNODE_IP | ||
thor --config-dir=/tmp --network /node/config/genesis.json --api-addr="0.0.0.0:8669" --api-cors="*" --bootnode "enode://e32e5960781ce0b43d8c2952eeea4b95e286b1bb5f8c1f0c9f09983ba7141d2fdd7dfbec798aefb30dcd8c3b9b7cda8e9a94396a0192bfa54ab285c2cec515ab@$BOOTNODE_IP:55555" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
version: "3.8" | ||
|
||
services: | ||
base-authority-node: | ||
image: ${THOR_IMAGE:-vechain/thor:latest} | ||
entrypoint: "/node/config/start.sh" | ||
volumes: | ||
- type: bind | ||
source: ./config | ||
target: /node/config | ||
- type: bind | ||
source: ./keys | ||
target: /node/keys | ||
healthcheck: | ||
test: ["CMD", "/node/config/health_check.sh"] | ||
interval: 1s | ||
timeout: 5s | ||
retries: 120 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
version: "3.8" | ||
|
||
services: | ||
|
||
thor-disco: | ||
image: ${THOR_IMAGE:-vechain/thor:latest} | ||
container_name: thor-disco | ||
entrypoint: "disco --keyhex=99f0500549792796c14fed62011a51081dc5b5e68fe8bd8a13b86be829c4fd36" | ||
|
||
authority-node-1: | ||
extends: | ||
file: docker-compose-base.yaml | ||
service: base-authority-node | ||
container_name: authority-node-1 | ||
environment: | ||
MASTER_KEY_ADDRESS: "435933c8064b4ae76be665428e0307ef2ccfbd68" | ||
ports: | ||
- "8669:8669" | ||
|
||
authority-node-2: | ||
extends: | ||
file: docker-compose-base.yaml | ||
service: base-authority-node | ||
container_name: authority-node-2 | ||
environment: | ||
MASTER_KEY_ADDRESS: "f370940abdbd2583bc80bfc19d19bc216c88ccf0" | ||
ports: | ||
- "8679:8669" | ||
|
||
authority-node-3: | ||
extends: | ||
file: docker-compose-base.yaml | ||
service: base-authority-node | ||
container_name: authority-node-3 | ||
environment: | ||
MASTER_KEY_ADDRESS: "0f872421dc479f3c11edd89512731814d0598db5" | ||
ports: | ||
- "8689:8669" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package network | ||
|
||
import ( | ||
"context" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/testcontainers/testcontainers-go/modules/compose" | ||
Check failure on line 6 in tests/e2e/network/docker.go GitHub Actions / unit_tests (1.21.x, ubuntu-latest)
Check failure on line 6 in tests/e2e/network/docker.go GitHub Actions / unit_tests (1.21.x, ubuntu-latest)
|
||
"testing" | ||
) | ||
|
||
type Network struct { | ||
stack *compose.ComposeStack | ||
} | ||
|
||
// StartCompose starts the docker-compose network and destroys it after the test | ||
func StartCompose(t *testing.T) { | ||
dc, err := compose.NewDockerCompose("network/docker-compose.yaml") | ||
assert.NoError(t, err, "NewDockerComposeAPI()") | ||
|
||
t.Cleanup(func() { | ||
assert.NoError(t, dc.Down(context.Background(), compose.RemoveOrphans(true), compose.RemoveImagesLocal), "compose.Down()") | ||
}) | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
t.Cleanup(cancel) | ||
|
||
assert.NoError(t, dc.Up(ctx, compose.Wait(true)), "compose.Up()") | ||
} |
21 changes: 21 additions & 0 deletions
21
tests/e2e/network/keys/0f872421dc479f3c11edd89512731814d0598db5/keystore.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"address": "0f872421dc479f3c11edd89512731814d0598db5", | ||
"id": "33eda5b7-140d-441d-b450-07ca28fb0105", | ||
"version": 3, | ||
"crypto": { | ||
"cipher": "aes-128-ctr", | ||
"cipherparams": { | ||
"iv": "182b783ea15a49b815042dd3a8bbc80e" | ||
}, | ||
"ciphertext": "2084fac13c2d3b3e45dd743766abcffe5c48e2d8169a895e7891235949fd3506", | ||
"kdf": "scrypt", | ||
"kdfparams": { | ||
"salt": "e5256c7b430ffefda1b1bcbef44af363eddf01ff8dc9112eb97324bfa6d388c6", | ||
"n": 131072, | ||
"dklen": 32, | ||
"p": 1, | ||
"r": 8 | ||
}, | ||
"mac": "b27043563629497c167a756eed7130079e7a4e7c5aa05fde67ed064a14e6f536" | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
tests/e2e/network/keys/0f872421dc479f3c11edd89512731814d0598db5/master.key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
f4a1a17039216f535d42ec23732c79943ffb45a089fbb78a14daad0dae93e991 |
Oops, something went wrong.