Skip to content

Commit

Permalink
Merge pull request #374 from multiversx/pretty-2024-02-02
Browse files Browse the repository at this point in the history
Run "pretty" (partially)
  • Loading branch information
andreibancioiu authored Feb 2, 2024
2 parents b76b8e2 + c3c1a2f commit 8d031be
Show file tree
Hide file tree
Showing 69 changed files with 501 additions and 442 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# See: https://EditorConfig.org
# VSCode plugin: https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
28 changes: 10 additions & 18 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,12 @@ module.exports = {
sourceType: "module",
},
plugins: ["@typescript-eslint/eslint-plugin"],
extends: [
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
extends: ["plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/recommended", "prettier"],
root: true,
env: {
node: true
node: true,
},
ignorePatterns: [
".eslintrc.js",
"node_modules",
"out",
"out-tests",
"out-browser",
"out-browser-tests",
],
ignorePatterns: [".eslintrc.js", "node_modules", "out", "out-tests", "out-browser", "out-browser-tests"],
rules: {
"@typescript-eslint/interface-name-prefix": "off",
"@typescript-eslint/explicit-function-return-type": "off",
Expand All @@ -34,10 +23,13 @@ module.exports = {
"@typescript-eslint/no-namespace": "warn",
"@typescript-eslint/no-var-requires": "warn",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-unused-vars": ["warn", {
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_"
}],
"@typescript-eslint/no-unused-vars": [
"warn",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
},
],
"prefer-const": "off",
},
};
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"singleQuote": false,
"trailingComma": "all",
"tabWidth": 4
"tabWidth": 4,
"printWidth": 120
}
10 changes: 9 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
{
}
"editor.formatOnSave": true,
"editor.formatOnSaveMode": "file",
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
97 changes: 18 additions & 79 deletions package-lock.json

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

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@
"@typescript-eslint/eslint-plugin": "5.44.0",
"@typescript-eslint/parser": "5.44.0",
"eslint": "8.28.0",
"eslint-config-prettier": "8.5.0",
"eslint-plugin-prettier": "3.4.1",
"prettier": "2.2.1"
"eslint-config-prettier": "9.1.0",
"prettier": "3.2.4"
}
}
2 changes: 1 addition & 1 deletion src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class Account {
/**
* Updates account properties (such as nonce, balance).
*/
update(obj: { nonce: INonce, balance: IAccountBalance}) {
update(obj: { nonce: INonce; balance: IAccountBalance }) {
this.nonce = obj.nonce;
this.balance = obj.balance;
}
Expand Down
17 changes: 11 additions & 6 deletions src/address.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { assert } from "chai";
import { Address } from "./address";
import * as errors from "./errors";


describe("test address", () => {
let aliceBech32 = "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th";
let bobBech32 = "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx";
Expand Down Expand Up @@ -41,13 +40,19 @@ describe("test address", () => {
assert.throw(() => new Address("foo"), errors.ErrAddressCannotCreate);
assert.throw(() => new Address("a".repeat(7)), errors.ErrAddressCannotCreate);
assert.throw(() => new Address(Buffer.from("aaaa", "hex")), errors.ErrAddressCannotCreate);
assert.throw(() => new Address("erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2"), errors.ErrAddressCannotCreate);
assert.throw(() => new Address("xerd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz"), errors.ErrAddressCannotCreate);
assert.throw(
() => new Address("erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2"),
errors.ErrAddressCannotCreate,
);
assert.throw(
() => new Address("xerd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz"),
errors.ErrAddressCannotCreate,
);
});

it("should validate the address without throwing the error", () => {
assert.isTrue(Address.isValid(aliceBech32));
assert.isFalse(Address.isValid('xerd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz'));
assert.isFalse(Address.isValid('erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2'))
})
assert.isFalse(Address.isValid("xerd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz"));
assert.isFalse(Address.isValid("erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2"));
});
});
8 changes: 3 additions & 5 deletions src/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,12 @@ export class Address {
static isValid(value: string): boolean {
const decoded = bech32.decodeUnsafe(value);
const prefix = decoded?.prefix;
const pubkey = decoded
? Buffer.from(bech32.fromWords(decoded.words))
: undefined;
const pubkey = decoded ? Buffer.from(bech32.fromWords(decoded.words)) : undefined;

if (prefix !== HRP || pubkey?.length !== PUBKEY_LENGTH) {
return false;
}

return true;
}

Expand Down Expand Up @@ -205,7 +203,7 @@ export class Address {
toJSON(): object {
return {
bech32: this.bech32(),
pubkey: this.hex()
pubkey: this.hex(),
};
}

Expand Down
3 changes: 1 addition & 2 deletions src/asyncTimer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { assert } from "chai";
import * as errors from "./errors";
import { AsyncTimer } from "./asyncTimer";


describe("test asyncTimer", () => {
it("should start timer and resolve promise", async () => {
let timer = new AsyncTimer("test");
Expand All @@ -21,7 +20,7 @@ describe("test asyncTimer", () => {
let longPromise = longTimer.start(42000);

let shortTimerThenAbortLongTimer = shortPromise.then(() => longTimer.abort());
let longTimerThenCatchAbort = longPromise.catch(reason => error = reason);
let longTimerThenCatchAbort = longPromise.catch((reason) => (error = reason));

await Promise.all([shortTimerThenAbortLongTimer, longTimerThenCatchAbort]);

Expand Down
8 changes: 6 additions & 2 deletions src/compatibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ export class Compatibility {
}

if (!address || address.bech32() == "") {
console.warn(`${context}: address should be set; ${resolution}. In the future, this will throw an exception instead of emitting a WARN.`);
console.warn(
`${context}: address should be set; ${resolution}. In the future, this will throw an exception instead of emitting a WARN.`,
);
} else if (address.bech32() == Address.Zero().bech32()) {
console.warn(`${context}: address should not be the 'zero' address (also known as the 'contracts deployment address'); ${resolution}. In the future, this will throw an exception instead of emitting a WARN.`);
console.warn(
`${context}: address should not be the 'zero' address (also known as the 'contracts deployment address'); ${resolution}. In the future, this will throw an exception instead of emitting a WARN.`,
);
}
}
}
2 changes: 1 addition & 1 deletion src/gasEstimator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe("test gas estimator", () => {
gasPerDataByte: 3000,
gasCostESDTTransfer: 200000,
gasCostESDTNFTTransfer: 300000,
gasCostESDTNFTMultiTransfer: 400000
gasCostESDTNFTMultiTransfer: 400000,
});

assert.equal(estimator.forEGLDTransfer(0), 10000);
Expand Down
8 changes: 3 additions & 5 deletions src/gasEstimator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ export const DefaultGasConfiguration: IGasConfiguration = {
gasPerDataByte: 1500,
gasCostESDTTransfer: 200000,
gasCostESDTNFTTransfer: 200000,
gasCostESDTNFTMultiTransfer: 200000
gasCostESDTNFTMultiTransfer: 200000,
};

// Additional gas to account for eventual increases in gas requirements (thus avoid fast-breaking changes in clients of the library).
const ADDITIONAL_GAS_FOR_ESDT_TRANSFER = 100000;

// Additional gas to account for extra blockchain operations (e.g. data movement (between accounts) for NFTs),
// Additional gas to account for extra blockchain operations (e.g. data movement (between accounts) for NFTs),
// and for eventual increases in gas requirements (thus avoid fast-breaking changes in clients of the library).
const ADDITIONAL_GAS_FOR_ESDT_NFT_TRANSFER = 800000;

Expand All @@ -35,9 +35,7 @@ export class GasEstimator {
}

forEGLDTransfer(dataLength: number) {
const gasLimit =
this.gasConfiguration.minGasLimit +
this.gasConfiguration.gasPerDataByte * dataLength;
const gasLimit = this.gasConfiguration.minGasLimit + this.gasConfiguration.gasPerDataByte * dataLength;

return gasLimit;
}
Expand Down
2 changes: 1 addition & 1 deletion src/hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class Hash {

/**
* Creates a new Hash object.
*
*
* @param hash The hash, as a Buffer or a hex-encoded string.
*/
constructor(hash: Buffer | string) {
Expand Down
Loading

0 comments on commit 8d031be

Please sign in to comment.