Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feat/api/contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
oXtxNt9U committed Nov 28, 2024
2 parents 1f8456b + 8304bda commit a5728aa
Show file tree
Hide file tree
Showing 13 changed files with 880 additions and 990 deletions.
6 changes: 2 additions & 4 deletions packages/api-http/integration/routes/delegates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,8 @@ describe<{
await apiContext.walletRepository.save(delegates);
await apiContext.walletRepository.save(wallets);

const wallet = wallets[wallets.length - 1];

await assert.rejects(
async () => request(`/delegates/${wallet.address}/voters`, options),
async () => request(`/delegates/0x0000000000000000000000000000000000000001/voters`, options),
"Response code 404 (Not Found)",
);

Expand All @@ -99,7 +97,7 @@ describe<{
assert.equal(statusCode, 200);
assert.equal(
data.data,
wallets.filter((wallet) => wallet.attributes.vote === delegate.publicKey),
wallets.filter((wallet) => wallet.attributes.vote === delegate.address),
);
});

Expand Down
40 changes: 40 additions & 0 deletions packages/api-http/integration/routes/transactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import receiptTransactions from "../../test/fixtures/receipt_transactions.json";
import transactions from "../../test/fixtures/transactions.json";
import transactionSchemas from "../../test/fixtures/transactions_schemas.json";
import transactionTypes from "../../test/fixtures/transactions_types.json";
import wallets from "../../test/fixtures/wallets.json";
import { ApiContext, prepareSandbox } from "../../test/helpers/prepare-sandbox";
import { request } from "../../test/helpers/request";

Expand Down Expand Up @@ -54,6 +55,12 @@ describe<{
.filter((tx) => tx.data === "")
.sort((a, b) => Number(b.blockHeight) - Number(a.blockHeight)),
},
{
path: "/transactions?data=",
result: [...transactions]
.filter((tx) => tx.data === "")
.sort((a, b) => Number(b.blockHeight) - Number(a.blockHeight)),
},
{ path: "/transactions?data=88888888", result: [] },
{
path: "/transactions?data=6dd7d8ea",
Expand All @@ -70,6 +77,39 @@ describe<{
}
});

it("/transactions?address", async () => {
await apiContext.transactionRepository.save(transactions);
await apiContext.walletRepository.save(wallets);

const transaction = transactions[transactions.length - 1];
const testCases = [
{
path: `/transactions?senderAddress=${transaction.senderAddress}`,
result: [...transactions]
.filter((tx) => tx.senderAddress === transaction.senderAddress)
.sort((a, b) => Number(b.blockHeight) - Number(a.blockHeight)),
},
{
path: `/transactions?senderId=${transaction.senderAddress}`,
result: [...transactions]
.filter((tx) => tx.senderAddress === transaction.senderAddress)
.sort((a, b) => Number(b.blockHeight) - Number(a.blockHeight)),
},
{
path: `/transactions?address=${transaction.recipientAddress}`,
result: [...transactions]
.filter((tx) => tx.recipientAddress === transaction.recipientAddress)
.sort((a, b) => Number(b.blockHeight) - Number(a.blockHeight)),
},
];

for (const { path, result } of testCases) {
const { statusCode, data } = await request(path, options);
assert.equal(statusCode, 200);
assert.equal(data.data, result);
}
});
//
it("/transactions/{id}", async () => {
await apiContext.transactionRepository.save(transactions);

Expand Down
8 changes: 4 additions & 4 deletions packages/api-http/integration/routes/wallets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ describe<{
id: wallet.publicKey,
result: wallet,
},
{
id: wallet.attributes.username,
result: wallet,
},
// {
// id: wallet.attributes.username,
// result: wallet,
// },
];

for (const { id, result } of testCases) {
Expand Down
2 changes: 1 addition & 1 deletion packages/api-http/source/resources/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class TransactionResource implements Contracts.Api.Resource {
blockId: resource.blockId,

confirmations,
data: resource.data,
data: resource.data === "0x" ? "" : resource.data,
gasLimit: resource.gasLimit,

gasPrice: resource.gasPrice,
Expand Down
8 changes: 5 additions & 3 deletions packages/api-http/source/schemas/schemas.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Joi from "joi";

import { walletAddressSchema } from "./wallets.js";

// Old

export const blockId = Joi.alternatives().try(
Expand All @@ -12,7 +14,7 @@ export const orderBy = Joi.alternatives().try(
Joi.array().items(Joi.string().regex(/^[._a-z]{1,40}:(asc|desc)$/i)),
);

export const address = Joi.string().alphanum().max(96);
export const address = walletAddressSchema;

export const delegateIdentifier = Joi.string()
.regex(/^[\w!$&.@]+$/)
Expand Down Expand Up @@ -82,14 +84,14 @@ export const transactionCriteriaSchemas = {
asset: orContainsCriteria(Joi.object()),
blockId: orEqualCriteria(blockId),
data: orEqualCriteria(
Joi.alternatives().try(Joi.string().valid("0x"), Joi.string().hex({ prefix: "optional" }).max(10)),
Joi.alternatives().try(Joi.string().valid("", "0x"), Joi.string().hex({ prefix: "optional" }).max(10)),
),
gasFee: orNumericCriteria(Joi.number().integer().min(0)),
gasPrice: orNumericCriteria(Joi.number().integer().min(0)),
id: orEqualCriteria(Joi.string().hex().length(64)),
nonce: orNumericCriteria(Joi.number().integer().positive()),
recipientId: orEqualCriteria(address),
senderAddress: orEqualCriteria(Joi.string().hex().length(42)),
senderAddress: orEqualCriteria(address),
senderId: orEqualCriteria(address),
senderPublicKey: orEqualCriteria(Joi.string().hex().length(66)),
sequence: orNumericCriteria(Joi.number().integer().positive()),
Expand Down
4 changes: 2 additions & 2 deletions packages/api-http/source/schemas/wallets.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Schemas } from "@mainsail/api-common";
import Joi from "joi";

export const walletAddressSchema = Joi.string().alphanum(); /* TODO: .length(34); */
export const walletPublicKeySchema = Joi.string().hex(); /* TODO: .length(66); */
export const walletAddressSchema = Joi.string().hex({ prefix: true }).length(42);
export const walletPublicKeySchema = Joi.string().hex({ prefix: false }).length(66);
export const walletUsernameSchema = Joi.string().max(256);

export const walletId = Joi.alternatives().try(
Expand Down
6 changes: 3 additions & 3 deletions packages/api-http/test/fixtures/blocks.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"payloadLength": 0,
"payloadHash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"stateHash": "0000000000000000000000000000000000000000000000000000000000000000",
"generatorAddress": "bc8686be38237cd1a9bb5efa85743b0ba594c5d433cdd1e6bfd804de11d92924",
"generatorAddress": "0xAe44ad925374b90B5f2A285461A70D6ba655EE28",
"signature": "a712a6168944f712a5c0797b9928e1b795780784356ff79f14f02af8bedaa6c81a8f263087cd8669baf699ea4982942714ab8485f785c273161fc58bef7036baa41ab6c42e4ea2d531200697c84fc3a6199de33af281ad437bf8e2734543f311",
"commitRound": 0,
"validatorSet": "9007199254740991",
Expand Down Expand Up @@ -959,7 +959,7 @@
"payloadLength": 0,
"payloadHash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"stateHash": "0000000000000000000000000000000000000000000000000000000000000000",
"generatorAddress": "9c633b08c5d3b384fdb4edaa30a6f5532216395e0af5d621715ee3417b1d8d54",
"generatorAddress": "0x58712FE2A757d2240510eAc42086601B21EA741A",
"signature": "a29a2acef8498991fe3a43891c42d539a229643b3fadadb78512b7ff91de929aa650f46d874612704aae8a3a4429643e0c152bf43715daa912bdabb1e97b07167e92d7127e1c1d9e11e458c1ac8d40b15f53ce3c77ce7a64ba048b33be34582c",
"commitRound": 0,
"validatorSet": "9007199254740991",
Expand All @@ -980,7 +980,7 @@
"payloadLength": 33646,
"payloadHash": "27bfa6b30158f909716179a1bc18ddbdd52f5c7115212953596eb70698eb424a",
"stateHash": "0000000000000000000000000000000000000000000000000000000000000000",
"generatorAddress": "9c633b08c5d3b384fdb4edaa30a6f5532216395e0af5d621715ee3417b1d8d54",
"generatorAddress": "0x58712FE2A757d2240510eAc42086601B21EA741A",
"signature": "",
"commitRound": 0,
"validatorSet": "9007199254740991",
Expand Down
4 changes: 2 additions & 2 deletions packages/api-http/test/fixtures/delegate_blocks.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"payloadLength": 0,
"payloadHash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
"stateHash": "0000000000000000000000000000000000000000000000000000000000000000",
"generatorAddress": "9c633b08c5d3b384fdb4edaa30a6f5532216395e0af5d621715ee3417b1d8d54",
"generatorAddress": "0x58712FE2A757d2240510eAc42086601B21EA741A",
"signature": "a29a2acef8498991fe3a43891c42d539a229643b3fadadb78512b7ff91de929aa650f46d874612704aae8a3a4429643e0c152bf43715daa912bdabb1e97b07167e92d7127e1c1d9e11e458c1ac8d40b15f53ce3c77ce7a64ba048b33be34582c",
"commitRound": 0,
"validatorSet": "9007199254740991",
Expand All @@ -35,7 +35,7 @@
"reward": "0",
"payloadLength": 33646,
"payloadHash": "27bfa6b30158f909716179a1bc18ddbdd52f5c7115212953596eb70698eb424a",
"generatorAddress": "9c633b08c5d3b384fdb4edaa30a6f5532216395e0af5d621715ee3417b1d8d54",
"generatorAddress": "0x58712FE2A757d2240510eAc42086601B21EA741A",
"signature": "",
"commitRound": 0,
"validatorSet": "9007199254740991",
Expand Down
8 changes: 4 additions & 4 deletions packages/api-http/test/fixtures/delegates.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[
{
"address": "9c633b08c5d3b384fdb4edaa30a6f5532216395e0af5d621715ee3417b1d8d54",
"publicKey": "9c633b08c5d3b384fdb4edaa30a6f5532216395e0af5d621715ee3417b1d8d54",
"address": "0x58712FE2A757d2240510eAc42086601B21EA741A",
"publicKey": "023fbcf58a4dcddfda8240fd9e8f92081f058719a3772f3bf3519d7d069ee45e74",
"balance": "0",
"nonce": "0",
"attributes": {
"vote": "9c633b08c5d3b384fdb4edaa30a6f5532216395e0af5d621715ee3417b1d8d54",
"vote": "0x58712FE2A757d2240510eAc42086601B21EA741A",
"nonce": "0",
"balance": "13",
"publicKey": "9c633b08c5d3b384fdb4edaa30a6f5532216395e0af5d621715ee3417b1d8d54",
"publicKey": "023fbcf58a4dcddfda8240fd9e8f92081f058719a3772f3bf3519d7d069ee45e74",
"validatorRank": 13,
"validatorApproval": 1.8867924528301887,
"username": "genesis_13",
Expand Down
4 changes: 2 additions & 2 deletions packages/api-http/test/fixtures/transactions.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"sequence": 59,
"timestamp": "1728618018574",
"nonce": "0",
"senderPublicKey": "026ca1c7dee0077484706639523009189cbd58003fc96e5730cfa63fb1cc6b34e9",
"senderAddress": "0xB4e48Acd227b58B99425f482e55b9510BE40835B",
"senderPublicKey": "03f4cac5e34fe17ee0ba5a247d04350adfb67ffcabd74c29cca040e73788e7b2cb",
"senderAddress": "0xbCf7A45dBE4679E47dfDDca23f5cB1d6a4e73608",
"recipientAddress": "0x522B3294E6d06aA25Ad0f1B8891242E335D3B459",
"amount": "0",
"gasPrice": "0",
Expand Down
14 changes: 7 additions & 7 deletions packages/api-http/test/fixtures/wallet_transactions.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"nonce": "3",
"senderPublicKey": "ac9a09dd85af1203cb5054d3f258e469ff831bf0ff1ee2cd90d6a46e52d11bae",
"senderAddress": "0xdB1A9acDd71eb5F846059034EF6D2CB144cCd1A9",
"recipientAddress": "0x522B3294E6d06aA25Ad0f1B8891242E335D3B459",
"recipientAddress": "0xAbd7A9c2054a362431F03a07104B262779e32ae4",
"amount": "1000000000",
"gasPrice": "5",
"gasLimit": "200000",
Expand All @@ -22,9 +22,9 @@
"sequence": 0,
"timestamp": "1695350059144",
"nonce": "2",
"senderPublicKey": "180ce525730360ffdd05cd0195baa545fe0dc0243dc1362f856475f8c0429d71",
"senderAddress": "0xB4e48Acd227b58B99425f482e55b9510BE40835B",
"recipientAddress": "0x522B3294E6d06aA25Ad0f1B8891242E335D3B459",
"senderPublicKey": "023fbcf58a4dcddfda8240fd9e8f92081f058719a3772f3bf3519d7d069ee45e74",
"senderAddress": "0x58712FE2A757d2240510eAc42086601B21EA741A",
"recipientAddress": "0xAbd7A9c2054a362431F03a07104B262779e32ae4",
"amount": "1000000000",
"gasPrice": "5",
"gasLimit": "200000",
Expand All @@ -38,9 +38,9 @@
"sequence": 0,
"timestamp": "1695350051134",
"nonce": "1",
"senderPublicKey": "180ce525730360ffdd05cd0195baa545fe0dc0243dc1362f856475f8c0429d71",
"senderAddress": "0xB4e48Acd227b58B99425f482e55b9510BE40835B",
"recipientAddress": "0x522B3294E6d06aA25Ad0f1B8891242E335D3B459",
"senderPublicKey": "023fbcf58a4dcddfda8240fd9e8f92081f058719a3772f3bf3519d7d069ee45e74",
"senderAddress": "0x58712FE2A757d2240510eAc42086601B21EA741A",
"recipientAddress": "0xAbd7A9c2054a362431F03a07104B262779e32ae4",
"amount": "1000000000",
"gasPrice": "5",
"gasLimit": "200000",
Expand Down
Loading

0 comments on commit a5728aa

Please sign in to comment.