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

dev into main #50

Merged
merged 26 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d0178a0
Add test to ensure no regression on the stack trace issue
lcswillems Nov 10, 2023
4d14a2c
Merge pull request #40 from arda-org/fix-stack-trace
lcswillems Nov 10, 2023
e9bb17d
Fix request xEGLD
lcswillems Nov 11, 2023
ca4d317
Merge pull request #41 from arda-org/fix-request-xegld
lcswillems Nov 11, 2023
6c12875
Improve backup sentence
lcswillems Nov 11, 2023
3669a25
Use relative dir for cd
lcswillems Nov 11, 2023
f68857d
Fix and uniformize interaction errors
lcswillems Nov 11, 2023
530bf75
Merge pull request #42 from arda-org/fix-and-uniformize-interaction-e…
lcswillems Nov 11, 2023
e551347
Add hex address
lcswillems Nov 11, 2023
2c76bee
Merge pull request #43 from arda-org/feat-hex-address-and-refactoring
lcswillems Nov 11, 2023
08a7892
Make simulnet working with never set address
lcswillems Nov 12, 2023
224f522
Merge pull request #44 from arda-org/fix-empty-address
lcswillems Nov 12, 2023
7afd554
Uniformize address names
lcswillems Nov 12, 2023
bb7724e
Fixes
lcswillems Nov 12, 2023
a15f5bd
Merge pull request #45 from arda-org/uniformize-address-names
lcswillems Nov 12, 2023
3ca1d37
Add response in errors
lcswillems Nov 12, 2023
f1c6958
Merge pull request #46 from arda-org/add-response-in-errors
lcswillems Nov 12, 2023
9dc1166
Release @xsuite/simulnet@0.0.8 xsuite@0.0.37
lcswillems Nov 12, 2023
72e4f14
Fix typo
lcswillems Nov 13, 2023
b42c711
Make gasLimit mandatory when creating a world
lcswillems Nov 13, 2023
04a266f
Merge pull request #47 from arda-org/fix-mandatory-gas-limit
lcswillems Nov 13, 2023
855274a
Add explorer URL
lcswillems Nov 18, 2023
c7fdc5e
Merge pull request #48 from arda-org/feat-explorer-url
lcswillems Nov 18, 2023
cf8ff52
Default options for new methods
lcswillems Nov 19, 2023
e8c1625
Merge pull request #49 from arda-org/new-default-values
lcswillems Nov 19, 2023
69fd7bb
Release @xsuite/simulnet@0.0.9 xsuite@0.0.38
lcswillems Nov 19, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
node-version: 18
pnpm-version: 8

- name: Buid xsuite
- name: Build xsuite
run: pnpm build-xsuite

- name: Build docs
Expand Down
9 changes: 4 additions & 5 deletions contracts/blank/interact/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { envChain, World } from "xsuite";
import data from "./data.json";

const world = World.new({
proxyUrl: envChain.publicProxyUrl(),
chainId: envChain.id(),
gasPrice: 1000000000,
});

const loadWallet = () => world.newWalletFromFile("wallet.json");
Expand All @@ -19,7 +17,8 @@ program.command("deploy").action(async () => {
codeMetadata: ["upgradeable"],
gasLimit: 20_000_000,
});
console.log("Result:", result);
console.log("Transaction:", result.tx.explorerUrl);
console.log("Contract:", result.contract.explorerUrl);
});

program.command("upgrade").action(async () => {
Expand All @@ -30,7 +29,7 @@ program.command("upgrade").action(async () => {
codeMetadata: ["upgradeable"],
gasLimit: 20_000_000,
});
console.log("Result:", result);
console.log("Transaction:", result.tx.explorerUrl);
});

program.command("ClaimDeveloperRewards").action(async () => {
Expand All @@ -40,7 +39,7 @@ program.command("ClaimDeveloperRewards").action(async () => {
funcName: "ClaimDeveloperRewards",
gasLimit: 10_000_000,
});
console.log("Result:", result);
console.log("Transaction:", result.tx.explorerUrl);
});

program.parse(process.argv);
9 changes: 4 additions & 5 deletions contracts/vested-transfers/interact/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { envChain, World } from "xsuite";
import data from "./data.json";

const world = World.new({
proxyUrl: envChain.publicProxyUrl(),
chainId: envChain.id(),
gasPrice: 1000000000,
});

const loadWallet = () => world.newWalletFromFile("wallet.json");
Expand All @@ -19,7 +17,8 @@ program.command("deploy").action(async () => {
codeMetadata: ["upgradeable"],
gasLimit: 100_000_000,
});
console.log("Result:", result);
console.log("Transaction:", result.tx.explorerUrl);
console.log("Contract:", result.contract.explorerUrl);
});

program.command("upgrade").action(async () => {
Expand All @@ -30,7 +29,7 @@ program.command("upgrade").action(async () => {
codeMetadata: ["upgradeable"],
gasLimit: 100_000_000,
});
console.log("Result:", result);
console.log("Transaction:", result.tx.explorerUrl);
});

program.command("ClaimDeveloperRewards").action(async () => {
Expand All @@ -40,7 +39,7 @@ program.command("ClaimDeveloperRewards").action(async () => {
funcName: "ClaimDeveloperRewards",
gasLimit: 10_000_000,
});
console.log("Result:", result);
console.log("Transaction:", result.tx.explorerUrl);
});

program.parse(process.argv);
2 changes: 1 addition & 1 deletion xsuite-simulnet/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xsuite/simulnet",
"version": "0.0.7",
"version": "0.0.9",
"license": "MIT",
"scripts": {
"build": "run-script-os",
Expand Down
17 changes: 13 additions & 4 deletions xsuite-simulnet/src/handleAddress.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"

"github.com/go-chi/chi"
worldmock "github.com/multiversx/mx-chain-vm-v1_4-go/mock/world"
)

func (ae *Executor) HandleAddress(r *http.Request) (interface{}, error) {
Expand All @@ -14,7 +15,7 @@ func (ae *Executor) HandleAddress(r *http.Request) (interface{}, error) {
if err != nil {
return nil, err
}
account := ae.vmTestExecutor.World.AcctMap.GetAccount(address)
account := ae.getAccount(address)
jData := map[string]interface{}{
"data": map[string]interface{}{
"account": map[string]interface{}{
Expand All @@ -37,7 +38,7 @@ func (ae *Executor) HandleAddressNonce(r *http.Request) (interface{}, error) {
if err != nil {
return nil, err
}
account := ae.vmTestExecutor.World.AcctMap.GetAccount(address)
account := ae.getAccount(address)
jData := map[string]interface{}{
"data": map[string]interface{}{
"nonce": account.Nonce,
Expand All @@ -53,7 +54,7 @@ func (ae *Executor) HandleAddressBalance(r *http.Request) (interface{}, error) {
if err != nil {
return nil, err
}
account := ae.vmTestExecutor.World.AcctMap.GetAccount(address)
account := ae.getAccount(address)
jData := map[string]interface{}{
"data": map[string]interface{}{
"balance": account.Balance.String(),
Expand All @@ -69,7 +70,7 @@ func (ae *Executor) HandleAddressKeys(r *http.Request) (interface{}, error) {
if err != nil {
return nil, err
}
account := ae.vmTestExecutor.World.AcctMap.GetAccount(address)
account := ae.getAccount(address)
jPairs := map[string]string{}
for k, v := range account.Storage {
if len(v) > 0 {
Expand All @@ -84,3 +85,11 @@ func (ae *Executor) HandleAddressKeys(r *http.Request) (interface{}, error) {
}
return jData, nil
}

func (ae *Executor) getAccount(address []byte) *worldmock.Account {
account, ok := ae.vmTestExecutor.World.AcctMap[string(address)]
if ok {
return account
}
return ae.vmTestExecutor.World.AcctMap.CreateAccount(address, ae.vmTestExecutor.World)
}
1 change: 1 addition & 0 deletions xsuite-simulnet/src/handleTransaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ func (ae *Executor) HandleTransactionSend(r *http.Request) (interface{}, error)
ae.txResps[txHash] = map[string]interface{}{
"data": map[string]interface{}{
"transaction": map[string]interface{}{
"hash": txHash,
"status": "success",
"logs": logs,
"smartContractResults": smartContractResults,
Expand Down
2 changes: 1 addition & 1 deletion xsuite/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xsuite",
"version": "0.0.36",
"version": "0.0.38",
"license": "MIT",
"bin": {
"xsuite": "cli.js"
Expand Down
65 changes: 29 additions & 36 deletions xsuite/src/cli/cmd.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ test("new-wallet --wallet wallet.json", async () => {
chalk.bold.blue("Private key:"),
...keystore.mnemonicWords.map((w, i) => ` ${i + 1}. ${w}`),
"",
chalk.bold.yellow(
"Don't forget to backup the private key in a secure place.",
),
chalk.bold.yellow("Please backup the private key in a secure place."),
"",
]);
});
Expand Down Expand Up @@ -79,9 +77,7 @@ test("new-wallet --wallet wallet.json --password 1234", async () => {
chalk.bold.blue("Private key:"),
...keystore.mnemonicWords.map((w, i) => ` ${i + 1}. ${w}`),
"",
chalk.bold.yellow(
"Don't forget to backup the private key in a secure place.",
),
chalk.bold.yellow("Please backup the private key in a secure place."),
"",
]);
});
Expand All @@ -102,33 +98,28 @@ test("request-xegld --wallet wallet.json", async () => {
const walletPath = path.resolve("wallet.json");
const signer = Keystore.createFile_unsafe(walletPath, "1234").newSigner();
const address = signer.toString();
let numBalanceReqs = 0;
let balances: number[] = [];
const server = setupServer(
http.get("https://devnet-api.multiversx.com/blocks/latest", () => {
return Response.json({
hash: "103b656af4fa9625962c5978e8cf69aca6918eb146a495bcf474f1c6a922be93",
});
}),
http.get("https://devnet-api.multiversx.com/blocks", () => {
return Response.json([
{
hash: "103b656af4fa9625962c5978e8cf69aca6918eb146a495bcf474f1c6a922be93",
},
]);
}),
http.get("https://devnet-api.multiversx.com/blocks/latest", () =>
Response.json({ hash: "" }),
),
http.get("https://devnet-api.multiversx.com/blocks", () =>
Response.json([{ hash: "" }]),
),
http.get(
`https://devnet-gateway.multiversx.com/address/${address}/balance`,
() => {
numBalanceReqs += 1;
const balance = `${30n * 10n ** 18n * BigInt(numBalanceReqs)}`;
const balance = `${BigInt(balances.shift() ?? 0) * 10n ** 18n}`;
return Response.json({ code: "successful", data: { balance } });
},
),
);
server.listen();
stdoutInt.start();
input.injected.push("1234", "1234");
balances = [0, 1];
await run(`request-xegld --wallet ${walletPath}`);
balances = [0, 10];
await run(`request-xegld --wallet ${walletPath} --password 1234`);
stdoutInt.stop();
server.close();
Expand All @@ -137,18 +128,18 @@ test("request-xegld --wallet wallet.json", async () => {
`Loading keystore wallet at "${walletPath}"...`,
"Enter password: ",
"",
`Claiming 30 xEGLD for address "${address}"...`,
`Claiming xEGLD for address "${address}"...`,
"",
"Open the URL and request tokens:",
splittedStdoutData.at(6),
"",
chalk.green("Wallet well received 30 xEGLD."),
`Claiming 30 xEGLD for address "${address}"...`,
chalk.green("Wallet well received 1 xEGLD."),
`Claiming xEGLD for address "${address}"...`,
"",
"Open the URL and request tokens:",
splittedStdoutData.at(12),
"",
chalk.green("Wallet well received 30 xEGLD."),
chalk.green("Wallet well received 10 xEGLD."),
"",
]);
});
Expand All @@ -173,10 +164,11 @@ test("new --dir contract && build --locked && build -r && test-rust && test-scen
await run("new --dir contract");
stdoutInt.stop();
expect(fs.readdirSync(process.cwd()).length).toEqual(1);
const dirPath = path.resolve("contract");
const dir = "contract";
const absDir = path.resolve(dir);
expect(stdoutInt.data.split("\n")).toEqual([
chalk.blue(
`Downloading contract ${chalk.magenta("blank")} in "${dirPath}"...`,
`Downloading contract ${chalk.magenta("blank")} in "${absDir}"...`,
),
"",
chalk.blue("Installing packages..."),
Expand All @@ -185,7 +177,7 @@ test("new --dir contract && build --locked && build -r && test-rust && test-scen
chalk.blue("Initialized a git repository."),
"",
chalk.green(
`Successfully created ${chalk.magenta("blank")} in "${dirPath}".`,
`Successfully created ${chalk.magenta("blank")} in "${absDir}".`,
),
"",
"Inside that directory, you can run several commands:",
Expand All @@ -201,20 +193,20 @@ test("new --dir contract && build --locked && build -r && test-rust && test-scen
"",
"We suggest that you begin by typing:",
"",
chalk.cyan(` cd ${dirPath}`),
chalk.cyan(` cd ${dir}`),
chalk.cyan(" npm run build"),
"",
]);

const targetDir = path.join(__dirname, "..", "..", "..", "target");
process.chdir(dirPath);
process.chdir(absDir);

stdoutInt.start();
await run(`build --locked --target-dir ${targetDir}`);
stdoutInt.stop();
expect(stdoutInt.data.split("\n")).toEqual([
chalk.blue("Building contract..."),
`(1/1) Building "${dirPath}"...`,
`(1/1) Building "${absDir}"...`,
chalk.cyan(
`$ cargo run --target-dir ${targetDir} build --locked --target-dir ${targetDir}`,
),
Expand All @@ -226,7 +218,7 @@ test("new --dir contract && build --locked && build -r && test-rust && test-scen
stdoutInt.stop();
expect(stdoutInt.data.split("\n")).toEqual([
chalk.blue("Building contract..."),
`(1/1) Building "${dirPath}"...`,
`(1/1) Building "${absDir}"...`,
chalk.cyan(
`$ cargo run --target-dir ${targetDir} build --target-dir ${targetDir}`,
),
Expand Down Expand Up @@ -263,11 +255,12 @@ test(`new --starter vested-transfers --dir contract --no-git --no-install`, asyn
stdoutInt.stop();
expect(fs.readdirSync(process.cwd()).length).toEqual(1);
const contractChalk = chalk.magenta(contract);
const dirPath = path.resolve("contract");
const dir = "contract";
const absDir = path.resolve(dir);
expect(stdoutInt.data.split("\n")).toEqual([
chalk.blue(`Downloading contract ${contractChalk} in "${dirPath}"...`),
chalk.blue(`Downloading contract ${contractChalk} in "${absDir}"...`),
"",
chalk.green(`Successfully created ${contractChalk} in "${dirPath}".`),
chalk.green(`Successfully created ${contractChalk} in "${absDir}".`),
"",
"Inside that directory, you can run several commands:",
"",
Expand All @@ -282,7 +275,7 @@ test(`new --starter vested-transfers --dir contract --no-git --no-install`, asyn
"",
"We suggest that you begin by typing:",
"",
chalk.cyan(` cd ${dirPath}`),
chalk.cyan(` cd ${dir}`),
chalk.cyan(" npm run build"),
"",
]);
Expand Down
10 changes: 6 additions & 4 deletions xsuite/src/cli/newCmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ const action = async ({
install?: boolean;
git?: boolean;
}) => {
dir = path.resolve(dir);
const absDir = path.resolve(dir);
if (fs.existsSync(dir)) {
logError(`Directory already exists at "${dir}".`);
logError(`Directory already exists at "${absDir}".`);
return;
} else {
fs.mkdirSync(dir, { recursive: true });
}
logTitle(`Downloading contract ${chalk.magenta(starter)} in "${dir}"...`);
logTitle(`Downloading contract ${chalk.magenta(starter)} in "${absDir}"...`);
await downloadAndExtractContract(starter, dir);
if (install) {
log();
Expand All @@ -53,7 +53,9 @@ const action = async ({
}
log();
log(
chalk.green(`Successfully created ${chalk.magenta(starter)} in "${dir}".`),
chalk.green(
`Successfully created ${chalk.magenta(starter)} in "${absDir}".`,
),
);
log();
log("Inside that directory, you can run several commands:");
Expand Down
6 changes: 1 addition & 5 deletions xsuite/src/cli/newWalletCmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,5 @@ const action = async ({
log(chalk.bold.blue("Private key:"));
log(keystore.mnemonicWords.map((w, i) => ` ${i + 1}. ${w}`).join("\n"));
log();
log(
chalk.bold.yellow(
`Don't forget to backup the private key in a secure place.`,
),
);
log(chalk.bold.yellow(`Please backup the private key in a secure place.`));
};
Loading