Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add entrypoints #538

Merged
merged 3 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
71 changes: 55 additions & 16 deletions src/entrypoints/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,65 @@ export interface EntrypointConfig {
chainId: string;
}

export class TestnetEntrypointConfig implements EntrypointConfig {
networkProviderUrl = "https://testnet-api.multiversx.com";
networkProviderKind = "api";
chainId = "T";
export class TestnetEntrypointConfig {
networkProviderUrl: string;
networkProviderKind: string;
chainId: string;

constructor({
networkProviderUrl = "https://testnet-api.multiversx.com",
networkProviderKind = "api",
chainId = "T",
}: Partial<EntrypointConfig> = {}) {
this.networkProviderUrl = networkProviderUrl;
this.networkProviderKind = networkProviderKind;
this.chainId = chainId;
}
}

export class DevnetEntrypointConfig implements EntrypointConfig {
networkProviderUrl = "https://devnet-api.multiversx.com";
networkProviderKind = "api";
chainId = "D";
export class DevnetEntrypointConfig {
networkProviderUrl: string;
networkProviderKind: string;
chainId: string;
constructor({
networkProviderUrl = "https://devnet-api.multiversx.com",
networkProviderKind = "api",
chainId = "D",
}: Partial<EntrypointConfig> = {}) {
this.networkProviderUrl = networkProviderUrl;
this.networkProviderKind = networkProviderKind;
this.chainId = chainId;
}
}

export class MainnetEntrypointConfig implements EntrypointConfig {
networkProviderUrl = "https://api.multiversx.com";
networkProviderKind = "api";
chainId = "1";
export class MainnetEntrypointConfig {
networkProviderUrl: string;
networkProviderKind: string;
chainId: string;

constructor({
networkProviderUrl = "https://api.multiversx.com",
networkProviderKind = "api",
chainId = "1",
}: Partial<EntrypointConfig> = {}) {
this.networkProviderUrl = networkProviderUrl;
this.networkProviderKind = networkProviderKind;
this.chainId = chainId;
}
}

export class LocalnetEntrypointConfig implements EntrypointConfig {
networkProviderUrl = "http://localhost:7950";
networkProviderKind = "proxy";
chainId = "localnet";
export class LocalnetEntrypointConfig {
networkProviderUrl: string;
networkProviderKind: string;
chainId: string;

constructor({
networkProviderUrl = "http://localhost:7950",
networkProviderKind = "proxy",
chainId = "localnet",
}: Partial<EntrypointConfig> = {}) {
this.networkProviderUrl = networkProviderUrl;
this.networkProviderKind = networkProviderKind;
this.chainId = chainId;
}
}
8 changes: 5 additions & 3 deletions src/entrypoints/entrypoints.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe("TestEntrypoint", () => {
this.timeout(30000);
const abi = await loadAbiRegistry("src/testdata/adder.abi.json");
const sender = Account.newFromPem(alicePem.pemFileText);
const accountAddress = new Address(sender.address.bech32());
const accountAddress = new Address(sender.address);
sender.nonce = await entrypoint.recallAccountNonce(accountAddress);

const controller = entrypoint.createSmartContractController(abi);
Expand Down Expand Up @@ -105,7 +105,7 @@ describe("TestEntrypoint", () => {
transaction.signature = await sender.sign(txComputer.computeBytesForSigning(transaction));

const relayedController = entrypoint.createRelayedController();
const relayedTransaction = relayedController.createRelayedV2Transaction(
const relayedTransaction = await relayedController.createRelayedV2Transaction(
relayer,
BigInt(relayer.getNonceThenIncrement().valueOf()),
{
Expand All @@ -114,6 +114,8 @@ describe("TestEntrypoint", () => {
},
);

assert.equal((await relayedTransaction).chainID, "D");
assert.equal(relayedTransaction.chainID, "D");
assert.deepEqual(transaction.data, Buffer.from("hello"));
assert.equal(relayedTransaction.gasLimit, 0n);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The gasLimit of the relayed transaction should not be 0, the issue is here.
And I meant to assert on the data field of the relayed transaction.

});
});
42 changes: 21 additions & 21 deletions src/entrypoints/entrypoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ class NetworkEntrypoint {
private networkProvider: ApiNetworkProvider | ProxyNetworkProvider;
private chainId: string;

constructor(networkProviderUrl: string, networkProviderKind: string, chainId: string) {
if (networkProviderKind === "proxy") {
this.networkProvider = new ProxyNetworkProvider(networkProviderUrl);
} else if (networkProviderKind === "api") {
this.networkProvider = new ApiNetworkProvider(networkProviderUrl);
constructor(options: { networkProviderUrl: string; networkProviderKind: string; chainId: string }) {
if (options.networkProviderKind === "proxy") {
this.networkProvider = new ProxyNetworkProvider(options.networkProviderUrl);
} else if (options.networkProviderKind === "api") {
this.networkProvider = new ApiNetworkProvider(options.networkProviderUrl);
} else {
throw new ErrInvalidNetworkProviderKind();
}

this.chainId = chainId;
this.chainId = options.chainId;
}

async signTransaction(transaction: Transaction, account: IAccount): Promise<void> {
Expand Down Expand Up @@ -111,32 +111,32 @@ class NetworkEntrypoint {
export class TestnetEntrypoint extends NetworkEntrypoint {
constructor(url?: string, kind?: string) {
const entrypointConfig = new TestnetEntrypointConfig();
super(
url || entrypointConfig.networkProviderUrl,
kind || entrypointConfig.networkProviderKind,
entrypointConfig.chainId,
);
super({
networkProviderUrl: url || entrypointConfig.networkProviderUrl,
networkProviderKind: kind || entrypointConfig.networkProviderKind,
chainId: entrypointConfig.chainId,
});
}
}

export class DevnetEntrypoint extends NetworkEntrypoint {
constructor(url?: string, kind?: string) {
const entrypointConfig = new DevnetEntrypointConfig();
super(
url || entrypointConfig.networkProviderUrl,
kind || entrypointConfig.networkProviderKind,
entrypointConfig.chainId,
);
super({
networkProviderUrl: url || entrypointConfig.networkProviderUrl,
networkProviderKind: kind || entrypointConfig.networkProviderKind,
chainId: entrypointConfig.chainId,
});
}
}

export class MainnetEntrypoint extends NetworkEntrypoint {
constructor(url?: string, kind?: string) {
const entrypointConfig = new MainnetEntrypointConfig();
super(
url || entrypointConfig.networkProviderUrl,
kind || entrypointConfig.networkProviderKind,
entrypointConfig.chainId,
);
super({
networkProviderUrl: url || entrypointConfig.networkProviderUrl,
networkProviderKind: kind || entrypointConfig.networkProviderKind,
chainId: entrypointConfig.chainId,
});
}
}
Loading