Skip to content

Commit

Permalink
Merge pull request #126 from ElrondNetwork/development
Browse files Browse the repository at this point in the history
Development into Main
  • Loading branch information
andreibancioiu authored Feb 10, 2022
2 parents 4b1e7ee + 8f3b617 commit 12a772f
Show file tree
Hide file tree
Showing 22 changed files with 331 additions and 207 deletions.
13 changes: 11 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes will be documented in this file.
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.

## [Unreleased]
- TBD

## [9.0.3]
- [Extension Provider throw error if tx canceled](https://github.com/ElrondNetwork/elrond-sdk-erdjs/pull/111).
- [Add fromAbiUrl() - paired with fromAbiPath()](https://github.com/ElrondNetwork/elrond-sdk-erdjs/pull/121).
- [Redo](https://github.com/ElrondNetwork/elrond-sdk-erdjs/pull/122) of PR [Better typing for ABI methods](https://github.com/ElrondNetwork/elrond-sdk-erdjs/pull/61).
- [For integration tests, resolve ambiguity between devnet & local-testnet](https://github.com/ElrondNetwork/elrond-sdk-erdjs/pull/124).
- [Fix `transaction.getAsOnNetwork()` to work both with `ProxyProvider` and `ApiProvider` (PARTIAL FIX)](https://github.com/ElrondNetwork/elrond-sdk-erdjs/pull/123).

## [9.0.2]
- [Fix recursivity issue when mapping types](https://github.com/ElrondNetwork/elrond-sdk-erdjs/pull/114).
Expand All @@ -27,9 +35,9 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
- Provider's send/sign transaction methonds responded with plainObject transactions instead of Transaction
- Added fromPlainObject method as a static method to transaction

- [Add signAuthToken method to HWProvider #73] (https://github.com/ElrondNetwork/elrond-sdk-erdjs/pull/73)
- [Add signAuthToken method to HWProvider #73](https://github.com/ElrondNetwork/elrond-sdk-erdjs/pull/73)
- [Fix for ignored config options in proxyProvider and apiProvider #76](https://github.com/ElrondNetwork/elrond-sdk-erdjs/pull/76)
- [Fix wallet logout/login redirect when using form submit] (https://github.com/ElrondNetwork/elrond-sdk-erdjs/pull/85)
- [Fix wallet logout/login redirect when using form submit](https://github.com/ElrondNetwork/elrond-sdk-erdjs/pull/85)
- [Fix ExtensionProvider sign message #86](https://github.com/ElrondNetwork/elrond-sdk-erdjs/pull/86)
- Add address to SignableMessage response

Expand All @@ -38,6 +46,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
- [Handle heterogeneous enums with fields](https://github.com/ElrondNetwork/elrond-sdk-erdjs/pull/98)
- [Background communication channel with extension popup](https://github.com/ElrondNetwork/elrond-sdk-erdjs/pull/103)


## [8.0.0]
- [ExtensionProvider] https://github.com/ElrondNetwork/elrond-sdk-erdjs/pull/66

Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
.PHONY: clean browser-tests

browser-tests: out-browser-tests/erdjs-tests-unit.js out-browser-tests/erdjs-tests-devnet.js out-browser-tests/erdjs-tests-testnet.js out-browser-tests/erdjs-tests-mainnet.js
browser-tests: out-browser-tests/erdjs-tests-unit.js out-browser-tests/erdjs-tests-localnet.js out-browser-tests/erdjs-tests-devnet.js out-browser-tests/erdjs-tests-testnet.js out-browser-tests/erdjs-tests-mainnet.js

out-browser-tests/erdjs-tests-unit.js: out-tests
npx browserify $(shell find out-tests -type f -name '*.js' ! -name '*.net.spec.*') --require buffer/:buffer -o out-browser-tests/erdjs-tests-unit.js --standalone erdjs-tests -p esmify

out-browser-tests/erdjs-tests-localnet.js: out-tests
npx browserify $(shell find out-tests -type f -name '*.js' ! -name '*.spec.*') $(shell find out-tests -type f -name '*.local.net.spec.js') --require buffer/:buffer -o out-browser-tests/erdjs-tests-localnet.js --standalone erdjs-tests -p esmify

out-browser-tests/erdjs-tests-devnet.js: out-tests
npx browserify $(shell find out-tests -type f -name '*.js' ! -name '*.spec.*') $(shell find out-tests -type f -name '*.dev.net.spec.js') --require buffer/:buffer -o out-browser-tests/erdjs-tests-devnet.js --standalone erdjs-tests -p esmify

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ In order to run the tests **on NodeJS**, do as follows:

```
npm run tests-unit
npm run tests-localnet
npm run tests-devnet
npm run tests-testnet
npm run tests-mainnet
Expand All @@ -203,4 +204,4 @@ make clean && npm run browser-tests

#### Notes

For the `devnet` tests, make sure you have a *devnet* running locally. A local *devnet* can be started from the Elrond IDE or from [erdpy](https://docs.elrond.com/developers/setup-a-local-testnet-erdpy).
For the `localnet` tests, make sure you have a *local testnet* up & running. A *local testnet* can be started from the Elrond IDE or from [erdpy](https://docs.elrond.com/developers/setup-local-testnet/).
28 changes: 17 additions & 11 deletions browser-tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,29 @@
<div class="col-sm-12">
<ul id="TestChoices" class="list-group">
<li class="list-group-item">
<button class="btn btn-link" onclick="runTests('/out-browser-tests/erdjs-tests-unit.js')">Unit
tests</button>
<button class="btn btn-link" onclick="runTests('/out-browser-tests/erdjs-tests-unit.js')">
Unit tests
</button>
</li>
<li class="list-group-item">
<button class="btn btn-link"
onclick="runTests('/out-browser-tests/erdjs-tests-devnet.js')">Integration tests -
devnet</button>
<button class="btn btn-link" onclick="runTests('/out-browser-tests/erdjs-tests-localnet.js')">
Integration tests - local testnet
</button>
</li>
<li class="list-group-item">
<button class="btn btn-link"
onclick="runTests('/out-browser-tests/erdjs-tests-testnet.js')">Integration tests -
testnet</button>
<button class="btn btn-link" onclick="runTests('/out-browser-tests/erdjs-tests-devnet.js')">
Integration tests - devnet
</button>
</li>
<li class="list-group-item">
<button class="btn btn-link"
onclick="runTests('/out-browser-tests/erdjs-tests-mainnet.js')">Integration tests -
mainnet</button>
<button class="btn btn-link" onclick="runTests('/out-browser-tests/erdjs-tests-testnet.js')">
Integration tests - testnet
</button>
</li>
<li class="list-group-item">
<button class="btn btn-link" onclick="runTests('/out-browser-tests/erdjs-tests-mainnet.js')">
Integration tests - mainnet
</button>
</li>
</ul>

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@elrondnetwork/erdjs",
"version": "9.0.2",
"version": "9.0.3",
"description": "Smart Contracts interaction framework",
"main": "out/index.js",
"types": "out/index.d.js",
Expand All @@ -11,6 +11,7 @@
"scripts": {
"test": "npm run tests-unit",
"tests-unit": "mocha $(find . -name '*.spec.ts' ! -name '*.net.spec.*')",
"tests-localnet": "mocha $(find . -name '*.local.net.spec.ts')",
"tests-devnet": "mocha $(find . -name '*.dev.net.spec.ts')",
"tests-testnet": "mocha $(find . -name '*.test.net.spec.ts')",
"tests-mainnet": "mocha $(find . -name '*.main.net.spec.ts')",
Expand Down
11 changes: 10 additions & 1 deletion src/apiProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as errors from "./errors";
import { Logger } from "./logger";
import { NetworkStake } from "./networkStake";
import { Stats } from "./stats";
import { TransactionHash } from "./transaction";
import { TransactionHash, TransactionStatus } from "./transaction";
import { TransactionOnNetwork } from "./transactionOnNetwork";
import { Token } from "./token";
import { NFTToken } from "./nftToken";
Expand Down Expand Up @@ -50,6 +50,15 @@ export class ApiProvider implements IApiProvider {
);
}

/**
* Queries the status of a {@link Transaction}.
*/
async getTransactionStatus(txHash: TransactionHash): Promise<TransactionStatus> {
return this.doGetGeneric(`transactions/${txHash.toString()}?fields=status`, (response) =>
new TransactionStatus(response.status)
);
}

async getToken(tokenIdentifier: string): Promise<Token> {
return this.doGetGeneric(`tokens/${tokenIdentifier}`, (response) => Token.fromHttpResponse(response));
}
Expand Down
11 changes: 8 additions & 3 deletions src/dapp/extensionProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,14 @@ export class ExtensionProvider implements IDappProvider {
from: this.account.address,
transactions: transactions,
});
txResponse = txResponse.map((transaction: any) =>
Transaction.fromPlainObject(transaction)
);
try {
txResponse = txResponse.map((transaction: any) =>
Transaction.fromPlainObject(transaction)
);
} catch (error) {
throw new Error("Transaction canceled.");
}

return txResponse;
}

Expand Down
30 changes: 22 additions & 8 deletions src/interactive.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { BalanceBuilder, Egld, ErrInvalidArgument, IProvider, NetworkConfig, ProxyProvider, SystemWrapper } from ".";
import { ApiProvider, BalanceBuilder, Egld, ErrInvalidArgument, IApiProvider, IProvider, NetworkConfig, ProxyProvider, SystemWrapper } from ".";
import { loadAndSyncTestWallets, TestWallet } from "./testutils";

type InteractivePackage = { erdSys: SystemWrapper, Egld: BalanceBuilder, wallets: Record<string, TestWallet> };

export async function setupInteractive(providerChoice: string): Promise<InteractivePackage> {
let provider = chooseProvider(providerChoice);
let provider = chooseProxyProvider(providerChoice);
return await setupInteractiveWithProvider(provider);
}

Expand All @@ -15,19 +15,33 @@ export async function setupInteractiveWithProvider(provider: IProvider): Promise
return { erdSys, Egld, wallets };
}

export function getProviders(): Record<string, ProxyProvider> {
return {
export function chooseProxyProvider(providerChoice: string): IProvider {
let providers: Record<string, IProvider> = {
"local-testnet": new ProxyProvider("http://localhost:7950", { timeout: 5000 }),
"elrond-testnet": new ProxyProvider("https://testnet-gateway.elrond.com", { timeout: 5000 }),
"elrond-devnet": new ProxyProvider("https://devnet-gateway.elrond.com", { timeout: 5000 }),
"elrond-mainnet": new ProxyProvider("https://gateway.elrond.com", { timeout: 20000 }),
};

let chosenProvider = providers[providerChoice];
if (chosenProvider) {
return chosenProvider;
}

throw new ErrInvalidArgument(`providerChoice is not recognized (must be one of: ${Object.keys(providers)})`);
}

export function chooseProvider(providerChoice: string): IProvider {
let providers = getProviders();
if (providerChoice in providers) {
return providers[providerChoice];
export function chooseApiProvider(providerChoice: string): IApiProvider {
let providers: Record<string, IApiProvider> = {
"elrond-devnet": new ApiProvider("https://devnet-api.elrond.com", { timeout: 5000 }),
"elrond-testnet": new ApiProvider("https://testnet-api.elrond.com", { timeout: 5000 }),
"elrond-mainnet": new ApiProvider("https://api.elrond.com", { timeout: 5000 })
};

let chosenProvider = providers[providerChoice];
if (chosenProvider) {
return chosenProvider;
}

throw new ErrInvalidArgument(`providerChoice is not recognized (must be one of: ${Object.keys(providers)})`);
}
33 changes: 17 additions & 16 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,25 @@ import { TransactionOnNetwork } from "./transactionOnNetwork";
import { Token } from "./token";
import BigNumber from "bignumber.js";

/**
* @deprecated This interface will be removed in a future release, upon merging {@link IProvider} and {@link IApiProvider}.
*/
export interface ITransactionFetcher {
/**
* Fetches the state of a {@link Transaction}.
*/
getTransaction(txHash: TransactionHash, hintSender?: Address, withResults?: boolean): Promise<TransactionOnNetwork>;

/**
* Queries the status of a {@link Transaction}.
*/
getTransactionStatus(txHash: TransactionHash): Promise<TransactionStatus>;
}

/**
* An interface that defines the endpoints of an HTTP API Provider.
*/
export interface IProvider {
export interface IProvider extends ITransactionFetcher {
/**
* Fetches the Network configuration.
*/
Expand Down Expand Up @@ -61,16 +76,6 @@ export interface IProvider {
*/
simulateTransaction(tx: Transaction): Promise<TransactionHash>;

/**
* Fetches the state of a {@link Transaction}.
*/
getTransaction(txHash: TransactionHash, hintSender?: Address, withResults?: boolean): Promise<TransactionOnNetwork>;

/**
* Queries the status of a {@link Transaction}.
*/
getTransactionStatus(txHash: TransactionHash): Promise<TransactionStatus>;

/**
* Get method that receives the resource url and on callback the method used to map the response.
*/
Expand All @@ -85,7 +90,7 @@ export interface IProvider {
/**
* An interface that defines the endpoints of an HTTP API Provider.
*/
export interface IApiProvider {
export interface IApiProvider extends ITransactionFetcher {
/**
* Fetches the Network Stake.
*/
Expand All @@ -94,10 +99,6 @@ export interface IApiProvider {
* Fetches the Network Stats.
*/
getNetworkStats(): Promise<Stats>;
/**
* Fetches the state of a {@link Transaction}.
*/
getTransaction(txHash: TransactionHash): Promise<TransactionOnNetwork>;

getToken(tokenIdentifier: string): Promise<Token>;

Expand Down
8 changes: 7 additions & 1 deletion src/smartcontracts/abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ export class SmartContractAbi {
}

static async fromAbiPath(abiPath: string): Promise<SmartContractAbi> {
let abiRegistry = await loadAbiRegistry([abiPath]);
let abiRegistry = await AbiRegistry.load({ files: [abiPath] });
let interfaceNames = abiRegistry.interfaces.map(iface => iface.name);
return new SmartContractAbi(abiRegistry, interfaceNames);
}

static async fromAbiUrl(abiUrl: string): Promise<SmartContractAbi> {
let abiRegistry = await AbiRegistry.load({ urls: [abiUrl] });
let interfaceNames = abiRegistry.interfaces.map(iface => iface.name);
return new SmartContractAbi(abiRegistry, interfaceNames);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import { Balance } from "../balance";
import BigNumber from "bignumber.js";
import { NetworkConfig } from "../networkConfig";
import { BytesValue } from "./typesystem/bytes";
import { chooseProvider } from "../interactive";
import { chooseProxyProvider } from "../interactive";


describe("test smart contract interactor", function () {
let checker = new StrictChecker();
let provider = chooseProvider("local-testnet");
let provider = chooseProxyProvider("local-testnet");
let alice: TestWallet;
let runner: DefaultInteractionRunner;
before(async function () {
Expand Down
4 changes: 2 additions & 2 deletions src/smartcontracts/query.main.net.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { ContractFunction } from "./function";
import { SmartContract } from "./smartContract";
import * as errors from "../errors";
import { AddressValue } from "./typesystem";
import { chooseProvider } from "../interactive";
import { chooseProxyProvider } from "../interactive";

describe("test queries on mainnet", function () {
let provider = chooseProvider("elrond-mainnet");
let provider = chooseProxyProvider("elrond-mainnet");
let delegationContract = new SmartContract({ address: new Address("erd1qqqqqqqqqqqqqpgqxwakt2g7u9atsnr03gqcgmhcv38pt7mkd94q6shuwt") });

it("delegation: should getTotalStakeByType", async () => {
Expand Down
Loading

0 comments on commit 12a772f

Please sign in to comment.