Skip to content
This repository has been archived by the owner on Dec 16, 2021. It is now read-only.

Commit

Permalink
feat: use DPP error classes (#164)
Browse files Browse the repository at this point in the history
Co-authored-by: Ivan Shumkov <ivan@shumkov.ru>
  • Loading branch information
Konstantin Shuplenkov and shumkov authored Sep 22, 2021
1 parent 5e18783 commit d6ea845
Show file tree
Hide file tree
Showing 12 changed files with 282 additions and 99 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DRIVE_BRANCH=v0.21-dev
DRIVE_BRANCH=update-dpp
DAPI_BRANCH=v0.21-dev
# DASHMATE_BRANCH=
# SDK_BRANCH=
DASHMATE_BRANCH=convenient-errors
#SDK_BRANCH=update-dpp
1 change: 1 addition & 0 deletions lib/test/createClientWithFundedWallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ async function createClientWithFundedWallet(HDPrivateKey = undefined) {
contractId: process.env.DPNS_CONTRACT_ID,
},
},
driveProtocolVersion: 1,
};

const faucetClient = createFaucetClient();
Expand Down
1 change: 1 addition & 0 deletions lib/test/createClientWithoutWallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function createClientWithoutWallet() {
contractId: process.env.DPNS_CONTRACT_ID,
},
},
driveProtocolVersion: 1,
});
}

Expand Down
1 change: 1 addition & 0 deletions lib/test/createFaucetClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function createFaucetClient() {
contractId: process.env.DPNS_CONTRACT_ID,
},
},
driveProtocolVersion: 1,
};

faucetClient = new Dash.Client({
Expand Down
300 changes: 234 additions & 66 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
"homepage": "https://github.com/dashevo/platform-test-suite#readme",
"dependencies": {
"@dashevo/dashcore-lib": "~0.19.25",
"@dashevo/dpns-contract": "github:dashevo/dpns-contract#update-dpp",
"@dashevo/dpns-contract": "github:dashevo/dpns-contract",
"@dashevo/feature-flags-contract": "github:dashevo/feature-flags-contract#update-dpp",
"@dashevo/dpp": "~0.21.0-dev.4",
"@dashevo/dpp": "~0.21.0-dev.7",
"@dashevo/grpc-common": "~0.4.0",
"@dashevo/merk": "git+https://github.com/dashevo/node-merk.git",
"@dashevo/wallet-lib": "~7.21.0-dev.6",
"@dashevo/wallet-lib": "~7.21.0-dev.8",
"blake3": "^2.1.4",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"dash": "~3.21.0-dev.6",
"dash": "~3.21.0-dev.7",
"dirty-chai": "^2.0.1",
"dotenv-safe": "^8.2.0",
"github-api": "^3.3.0",
Expand Down
2 changes: 2 additions & 0 deletions test/e2e/wallet.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('e2e', () => {
mnemonic,
waitForInstantLockTimeout: 120000,
},
driveProtocolVersion: 1,
});
});

Expand Down Expand Up @@ -101,6 +102,7 @@ describe('e2e', () => {
},
seeds: getDAPISeeds(),
network: process.env.NETWORK,
driveProtocolVersion: 1,
});

restoredAccount = await restoredWallet.getWalletAccount();
Expand Down
3 changes: 2 additions & 1 deletion test/functional/core/getBlockHash.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ describe('Core', () => {
}

expect(broadcastError).to.exist();
expect(broadcastError.name).to.equal('JsonRpcError');
expect(broadcastError.name).to.equal('ResponseError');
expect(broadcastError.message).contains('Block height out of range');
expect(broadcastError.code).to.equal(-32602);
});
});
});
2 changes: 1 addition & 1 deletion test/functional/core/getTransaction.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const {
PrivateKey,
} = require('@dashevo/dashcore-lib');

const NotFoundError = require('@dashevo/dapi-client/lib/errors/response/NotFoundError');
const NotFoundError = require('@dashevo/dapi-client/lib/transport/GrpcTransport/errors/NotFoundError');

const createFaucetClient = require('../../../lib/test/createFaucetClient');
const wait = require('../../../lib/wait');
Expand Down
6 changes: 4 additions & 2 deletions test/functional/platform/DataContract.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const getDataContractFixture = require(

const { executeProof, verifyProof } = require('@dashevo/merk');
const generateRandomIdentifier = require('@dashevo/dpp/lib/test/utils/generateRandomIdentifier');
const IdentityNotFoundError = require('@dashevo/dpp/lib/errors/consensus/signature/IdentityNotFoundError');
const { StateTransitionBroadcastError } = require('dash/build/src/errors/StateTransitionBroadcastError');
const createClientWithFundedWallet = require('../../../lib/test/createClientWithFundedWallet');
const testProofStructure = require('../../../lib/test/testProofStructure');
const parseStoreTreeProof = require('../../../lib/parseStoreTreeProof');
Expand Down Expand Up @@ -41,8 +43,8 @@ describe('Platform', () => {
broadcastError = e;
}

expect(broadcastError.message).to.equal(`16 UNAUTHENTICATED: Identity ${dataContractFixture.getOwnerId().toString()} not found`);
expect(broadcastError.code).to.equal(2000);
expect(broadcastError).to.be.an.instanceOf(StateTransitionBroadcastError);
expect(broadcastError.getCause()).to.be.an.instanceOf(IdentityNotFoundError);
});

it('should create new data contract with previously created identity as an owner', async () => {
Expand Down
10 changes: 4 additions & 6 deletions test/functional/platform/Document.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const getIdentityFixture = require(

const { signStateTransition } = require('dash/build/src/SDK/Client/Platform/signStateTransition');

const InvalidDocumentTypeError = require('@dashevo/dpp/lib/errors/consensus/basic/document/InvalidDocumentTypeError');
const { StateTransitionBroadcastError } = require('dash/build/src/errors/StateTransitionBroadcastError');
const createClientWithFundedWallet = require('../../../lib/test/createClientWithFundedWallet');

describe('Platform', () => {
Expand Down Expand Up @@ -82,12 +84,8 @@ describe('Platform', () => {
broadcastError = e;
}

expect(broadcastError).to.exist();
expect(
/INVALID_ARGUMENT: Data Contract \w* doesn't define document with type undefinedType/
.test(broadcastError.message),
).to.be.true();
expect(broadcastError.code).to.be.equal(1024);
expect(broadcastError).to.be.an.instanceOf(StateTransitionBroadcastError);
expect(broadcastError.getCause()).to.be.an.instanceOf(InvalidDocumentTypeError);
});

it('should fail to create a new document with an unknown owner', async () => {
Expand Down
41 changes: 25 additions & 16 deletions test/functional/platform/Identity.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ const { default: createIdentityTopUpTransition } = require('dash/build/src/SDK/C
const { default: createAssetLockTransaction } = require('dash/build/src/SDK/Client/Platform/createAssetLockTransaction');

const { PrivateKey } = require('@dashevo/dashcore-lib');
const { StateTransitionBroadcastError } = require('dash/build/src/errors/StateTransitionBroadcastError');
const InvalidInstantAssetLockProofSignatureError = require('@dashevo/dpp/lib/errors/consensus/basic/identity/InvalidInstantAssetLockProofSignatureError');
const IdentityAssetLockTransactionOutPointAlreadyExistsError = require('@dashevo/dpp/lib/errors/consensus/basic/identity/IdentityAssetLockTransactionOutPointAlreadyExistsError');
const BalanceIsNotEnoughError = require('@dashevo/dpp/lib/errors/consensus/fee/BalanceIsNotEnoughError');
const IdentityPublicKeyAlreadyExistsError = require('@dashevo/dpp/lib/errors/consensus/state/identity/IdentityPublicKeyAlreadyExistsError');

const waitForBlocks = require('../../../lib/waitForBlocks');
const waitForBalanceToChange = require('../../../lib/test/waitForBalanceToChange');

Expand Down Expand Up @@ -89,9 +95,10 @@ describe('Platform', () => {
broadcastError = e;
}

expect(broadcastError).to.exist();
expect(broadcastError.message).to.be.equal('3 INVALID_ARGUMENT: Invalid instant lock proof signature');
expect(broadcastError.code).to.be.equal(1042);
expect(broadcastError).to.be.an.instanceOf(StateTransitionBroadcastError);
expect(broadcastError.getCause()).to.be.an.instanceOf(
InvalidInstantAssetLockProofSignatureError,
);
});

it('should fail to create an identity with already used asset lock output', async () => {
Expand Down Expand Up @@ -142,9 +149,10 @@ describe('Platform', () => {
broadcastError = e;
}

expect(broadcastError).to.exist();
expect(broadcastError.message).to.satisfy((msg) => msg.startsWith('3 INVALID_ARGUMENT: Asset lock transaction'));
expect(broadcastError.code).to.be.equal(1033);
expect(broadcastError).to.be.an.instanceOf(StateTransitionBroadcastError);
expect(broadcastError.getCause()).to.be.an.instanceOf(
IdentityAssetLockTransactionOutPointAlreadyExistsError,
);
});

it('should fail to create an identity with already used public key', async () => {
Expand Down Expand Up @@ -184,7 +192,9 @@ describe('Platform', () => {

expect(broadcastError).to.exist();
expect(broadcastError.message).to.be.equal(`Identity public key ${identity.getPublicKeyById(0).hash().toString('hex')} already exists`);
expect(broadcastError.code).to.be.equal(4012);
expect(broadcastError.getCause()).to.be.an.instanceOf(
IdentityPublicKeyAlreadyExistsError,
);
});

it('should be able to get newly created identity', async () => {
Expand Down Expand Up @@ -350,12 +360,10 @@ describe('Platform', () => {
broadcastError = e;
}

expect(broadcastError).to.exist();
expect(
/FAILED_PRECONDITION: Failed precondition: Current credits balance \d* is not enough to pay \d* fee/
.test(broadcastError.message),
).to.be.true();
expect(broadcastError.code).to.be.equal(3000);
expect(broadcastError).to.be.an.instanceOf(StateTransitionBroadcastError);
expect(broadcastError.getCause()).to.be.an.instanceOf(
BalanceIsNotEnoughError,
);
});

it.skip('should fail top-up if instant lock is not valid', async () => {
Expand Down Expand Up @@ -474,9 +482,10 @@ describe('Platform', () => {
broadcastError = e;
}

expect(broadcastError).to.exist();
expect(broadcastError.message).to.satisfy((msg) => msg.startsWith('3 INVALID_ARGUMENT: Asset lock transaction'));
expect(broadcastError.code).to.be.equal(1033);
expect(broadcastError).to.be.an.instanceOf(StateTransitionBroadcastError);
expect(broadcastError.getCause()).to.be.an.instanceOf(
IdentityAssetLockTransactionOutPointAlreadyExistsError,
);
});
});

Expand Down

0 comments on commit d6ea845

Please sign in to comment.