Skip to content

Commit

Permalink
feat: create APIs for integrating with nano contracts (method, state,…
Browse files Browse the repository at this point in the history
… history) (#349)
  • Loading branch information
pedroferreira1 authored Apr 2, 2024
1 parent 40f9217 commit fb0ce45
Show file tree
Hide file tree
Showing 19 changed files with 1,675 additions and 10 deletions.
83 changes: 83 additions & 0 deletions __tests__/__fixtures__/http-fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -1011,8 +1011,91 @@ export default {
first_block_height: 1234,
},
},
'/transaction?id=5c02adea056d7b43e83171a0e2d226d564c791d583b32e9a404ef53a2e1b363a': {
success: true,
tx: {
hash: '5c02adea056d7b43e83171a0e2d226d564c791d583b32e9a404ef53a2e1b363a',
version: 4,
nc_blueprint_id: '3cb032600bdf7db784800e4ea911b10676fa2f67591f82bb62628c234e771595',
},
},
'/getmininginfo': {
success: true,
blocks: 1242,
},
'/nano_contract/state': {
success: true,
nc_id: '3cb032600bdf7db784800e4ea911b10676fa2f67591f82bb62628c234e771595',
blueprint_name: 'Bet',
fields: {
token_uid: { value: '00' },
total: { value: 300 },
final_result: { value: '1x0' },
oracle_script: { value: '76a91441c431ff7ad5d6ce5565991e3dcd5d9106cfd1e288ac' },
'withdrawals.a\'Wi8zvxdXHjaUVAoCJf52t3WovTZYcU9aX6\'': { value: 300 },
'address_details.a\'Wi8zvxdXHjaUVAoCJf52t3WovTZYcU9aX6\'': { value: { '1x0': 100 } },
}
},
'/nano_contract/history': {
success: true,
count: 100,
history: [{
hash: '5c02adea056d7b43e83171a0e2d226d564c791d583b32e9a404ef53a2e1b363a',
nonce: 0,
timestamp: 1572636346,
version: 4,
weight: 1,
signal_bits: 0,
parents: ['1234', '5678'],
inputs: [],
outputs: [],
metadata: {
hash: '5c02adea056d7b43e83171a0e2d226d564c791d583b32e9a404ef53a2e1b363a',
spent_outputs: [],
received_by: [],
children: [],
conflict_with: [],
voided_by: [],
twins: [],
accumulated_weight: 1,
score: 0,
height: 0,
min_height: 0,
feature_activation_bit_counts: null,
first_block: null,
validation: 'full'
},
tokens: [],
nc_id: '5c02adea056d7b43e83171a0e2d226d564c791d583b32e9a404ef53a2e1b363a',
nc_method: 'initialize',
nc_args: '0004313233340001000004654d8749',
nc_pubkey: '033f5d238afaa9e2218d05dd7fa50eb6f9e55431e6359e04b861cd991ae24dc655'
}]
},
'/nano_contract/blueprint': {
id: '3cb032600bdf7db784800e4ea911b10676fa2f67591f82bb62628c234e771595',
name: 'Test',
public_methods: {
initialize: {
args: [
{ type: 'int', name: 'a' },
{ type: 'bytes', name: 'b' }
]
},
bet: {
args: [
{ type: 'int', name: 'a' },
{ type: 'bytes', name: 'b' }
]
},
},
},
'/nano_contract/oracle-data': {
success: true,
oracleData: '1234'
},
'/nano_contract/oracle-signed-result': {
success: true,
signedResult: '123456,1x0,str'
},
};
6 changes: 5 additions & 1 deletion __tests__/integration/configuration/privnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

P2PKH_VERSION_BYTE: x49
MULTISIG_VERSION_BYTE: x87
NETWORK_NAME: privatenet
NETWORK_NAME: nano-testnet-alpha
BOOTSTRAP_DNS: []
ENABLE_PEER_WHITELIST: false

Expand All @@ -29,4 +29,8 @@ REWARD_SPEND_MIN_BLOCKS: 1

CHECKPOINTS: []

ENABLE_NANO_CONTRACTS: true
BLUEPRINTS:
3cb032600bdf7db784800e4ea911b10676fa2f67591f82bb62628c234e771595: Bet

extends: mainnet.yml
2 changes: 1 addition & 1 deletion __tests__/integration/configuration/settings-fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const defaultConfig = {
http_port: 8000,

// Hathor Full-node
network: 'privatenet',
network: 'testnet',
server: 'http://localhost:8083/v1a/',

// Tx Mining Service
Expand Down
9 changes: 6 additions & 3 deletions __tests__/integration/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ services:
# https://github.com/HathorNetwork/rfcs/blob/master/text/0033-private-network-guide.md

fullnode:
image: hathornetwork/hathor-core
image:
${HATHOR_LIB_INTEGRATION_TESTS_FULLNODE_IMAGE:-hathornetwork/hathor-core:experimental-nano-sdk-v1.1}
command: [
"run_node",
"--listen", "tcp:40404",
"--status", "8080",
"--test-mode-tx-weight",
"--wallet-index",
"--allow-mining-without-peers",
"--unsafe-mode", "privatenet",
"--unsafe-mode", "nano-testnet-alpha",
"--memory-storage",
"--nc-history-index",
]
environment:
HATHOR_CONFIG_YAML: privnet/conf/privnet.yml
Expand All @@ -29,7 +31,8 @@ services:
- hathor-privnet

tx-mining-service:
image: hathornetwork/tx-mining-service
image:
${HATHOR_LIB_INTEGRATION_TESTS_TXMINING_IMAGE:-hathornetwork/tx-mining-service}
depends_on:
- fullnode
ports:
Expand Down
2 changes: 1 addition & 1 deletion __tests__/integration/multisig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ describe('send tx (HTR)', () => {
});

it('should mount the transaction with the correct change outputs', async () => {
const network = new hathorLib.Network('privatenet');
const network = new hathorLib.Network('testnet');
const burnAddress = TestUtils.getBurnAddress();
const response = await TestUtils.request
.post('/wallet/p2sh/tx-proposal')
Expand Down
Loading

0 comments on commit fb0ce45

Please sign in to comment.