@@ -9,6 +9,8 @@ import { GenericAccount, AccountType } from "../../src/core/account";
99import { GenericNode } from "../../src/core/node";
1010import { GenericTransaction, TransactionStatus } from "../../src/core/transaction";
1111import { ZilliqaTransaction } from "../../src/blockchain/zilliqa/transaction";
12+ import { ZilliqaAccountUtils } from "../../src/blockchain/zilliqa/account-utils";
13+ const AccountUtils = new ZilliqaAccountUtils();
1214
1315import Ethereum from "../../src/blockchain/ethereum/class.index";
1416import Zilliqa from "../../src/blockchain/zilliqa/class.index";
@@ -17,21 +19,17 @@ import { Zilliqa as ZilliqaOfficial } from 'zilliqa-js';
1719import { Zilliqa as OfficialZilliqa } from '@zilliqa-js/zilliqa';
1820
1921import * as ZilliqaJsCrypto from "@zilliqa-js/crypto";
20- import { BN , Long } from '@zilliqa-js/util' ;
22+ import { BN, Long, bytes, units } from '@zilliqa-js/util';
2123import Signature from 'elliptic/lib/elliptic/ec/signature';
2224
23- // const pk = "891E98DBEF714F120958405F5CF1FA4F47496D0B287E514C1A7EC02805DA3C13";
2425const pk = "891E98DBEF714F120958405F5CF1FA4F47496D0B287E514C1A7EC02805DA3C13";
25-
26- // ionut
27- const testReceiverAddress = "0xee9d7b0a5cd3ff9fcdd3a44a6ee49ff9edfe382a" ;
26+ const testReceiverAddress = "0x99959F33842946AeF50A7573b8c3cBf04Df339C7";
2827
2928const mapper = new DynamicClassMapper();
3029mapper.collectClasses(Zilliqa.AvailableClasses);
3130mapper.collectClasses(Ethereum.AvailableClasses);
3231const mnemonic = "exchange neither monster ethics bless cancel ghost excite business record warfare invite";
3332
34- /*
3533describe("Zilliqa", async () => {
3634
3735 describe("Wallet with one Zilliqa account", async () => {
@@ -43,10 +41,10 @@ describe("Zilliqa", async () => {
4341 const blockchain = Blockchains.ZILLIQA;
4442
4543 const TestNode: GenericNode = defaultWallet.getNode( blockchain );
46- TestNode.init( TestNode.NETWORKS[ 1 ] ); // https://api-scilla.zilliqa.com/
44+ // TestNode.init( TestNode.NETWORKS[ 1 ] ); // https://api-scilla.zilliqa.com/
4745
48- // TestNode.init( TestNode. NETWORKS[ 0 ] ) ;
49- // TestNode.setCustomNetworkUrl("https://dev-test-api.aws.z7a.xyz/" );
46+ TestNode.NETWORKS[ 0 ].chainId = 62 ;
47+ TestNode.init( TestNode.NETWORKS[ 0 ] );
5048
5149 const AccountClassTypeString = GenericAccount.getImplementedClassName( Blockchains[blockchain] );
5250 const NodeClassTypeString = GenericNode.getImplementedClassName( Blockchains[blockchain] );
@@ -63,26 +61,44 @@ describe("Zilliqa", async () => {
6361
6462 it("Should have a balance", async () => {
6563 myNonce = await account.getNonce();
66- console.log( await account.getBalance() );
67- console.log( myNonce );
64+ const balance = await account.getBalance();
6865
69- });
66+ console.log( "Account: ", AccountUtils.toChecksumAddress( account.address ) );
67+ console.log( "Balance: ", balance.toString() );
68+ console.log( "Nonce: ", myNonce );
69+
70+ }).timeout(10000);
7071
7172 describe("send() signed transaction", async () => {
7273 it("debug", async () => {
7374 const nonce = await account.getNonce();
7475
76+ const amount = 10 * ( 10 ** 12);
77+ const txGasPrice = 1000 * (10 ** 6);
78+ const txGasLimit = 1;
79+
80+ // amount: units.toQa('10', units.Units.Zil), // Sending an amount in Zil and converting the amount to Qa.
81+ // gasPrice: units.toQa('10000', units.Units.Li), // gasPrice is measured in Li. 1 Li is 10^-6 Zil.
82+ // gasLimit: Long.fromNumber(1),
83+
84+ console.log( "amount: ", amount.toString() );
85+ console.log( "txGasPrice: ", txGasPrice.toString() );
86+ console.log( "txGasLimit: ", txGasLimit.toString() );
87+
88+ // testReceiverAddress.replace("0x", "").toLowerCase(),
7589 const transaction = account.buildTransferTransaction(
76- testReceiverAddress.replace("0x", "").toLowerCase( ),
77- 8 , // amount
78- nonce, // nonce
79- 10, // gasLimit
80- 100, // gasPrice
90+ AccountUtils.toChecksumAddress( testReceiverAddress ) .replace("0x", ""),
91+ amount , // amount
92+ nonce + 1, // nonce
93+ txGasLimit, // gasLimit
94+ txGasPrice, // gasPrice
8195 ) as ZilliqaTransaction;
8296
97+ console.log("\n", ">>>> Moonlet toParams:", "\n", transaction.toParams() );
98+
8399 await account.signTransaction( transaction );
84100
85- console.log("\n", ">>>> Moonlet txn: ", transaction.TXObject);
101+ console.log("\n", ">>>> Moonlet TXObject:", "\n ", transaction.TXObject);
86102
87103 await account.send( transaction );
88104
@@ -94,38 +110,55 @@ describe("Zilliqa", async () => {
94110
95111 }).timeout(10000);
96112 });
113+
97114 });
98115
116+ /*
99117 describe("Official Transaction Test", async () => {
100118
101119 it("Should work", async () => {
102120
103- const { BN, Long } = require('@zilliqa-js/util');
104-
105121 const { Transaction } = require('@zilliqa-js/account');
106-
107- const zilliqa = new OfficialZilliqa('https://api-scilla.zilliqa.com/');
122+ const zilliqa = new OfficialZilliqa('https://api.zilliqa.com/');
108123
109124 zilliqa.wallet.addByPrivateKey(pk);
125+ const add = ZilliqaJsCrypto.getAddressFromPrivateKey(pk);
126+ console.log('\nYour account address is:');
127+ console.log(`0x${add}`);
128+
129+ const CHAIN_ID = 62;
130+ const MSG_VERSION = 1;
131+ const VER = ( CHAIN_ID << 16 ) + MSG_VERSION;
132+
133+ try {
110134
111- const newtx = zilliqa.transactions.new({
112- version: 1,
113- toAddr: testReceiverAddress.replace("0x", "").toLowerCase(),
114- amount: new BN(8),
115- gasPrice: new BN(100),
116- // can be `number` if size is <= 2^53 (i.e., window.MAX_SAFE_INTEGER)
117- gasLimit: Long.fromNumber(10),
118- });
135+ const balance = await zilliqa.blockchain.getBalance(add);
136+ console.log('Your account balance is:');
137+ console.log(balance.result);
119138
120- console.log("newtx", newtx);
139+ const newtx = zilliqa.transactions.new({
140+ version: VER,
141+ toAddr: AccountUtils.toChecksumAddress( testReceiverAddress ).replace("0x", "").toLowerCase(),
142+ amount: units.toQa('10', units.Units.Zil), // Sending an amount in Zil and converting the amount to Qa.
143+ gasPrice: units.toQa('10000', units.Units.Li), // gasPrice is measured in Li. 1 Li is 10^-6 Zil.
144+ gasLimit: Long.fromNumber(1),
145+ });
121146
122- const tx = await zilliqa.blockchain.createTransaction(newtx);
123- console.log( tx );
147+ console.log("\nnewtx", newtx);
148+
149+ const tx = await zilliqa.blockchain.createTransaction(newtx);
150+ console.log("The transaction status is:");
151+ console.log(tx.receipt);
152+
153+ } catch (err) {
154+ console.log("\n", err);
155+ }
124156
125157 }).timeout(10000);
126158 });
159+ */
127160});
128- */
161+
129162/*
130163describe("Kaya - Moonlet Core - Wallet with one Zilliqa account", async () => {
131164
0 commit comments