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

Feat: blacklist whitelist contacts #1814

Merged
merged 23 commits into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
11 changes: 11 additions & 0 deletions __mocks__/AddressBookMock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { AddressBook, IContact } from 'symbol-address-book';

export const addressBookMock: AddressBook = new AddressBook();
const contact1: IContact = {
id: '5c9093c7-2da2-476e-bc28-87f24a83cd0c',
address: 'TAVVVJBBCTYJDWC7TQPSVNHK2IPNY6URKK4DTHY',
name: 'Alice',
phone: '+34 000000000',
isBlackListed: true,
};
addressBookMock.addContact(contact1);
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,25 @@ import TransactionListFilters from '@/components/TransactionList/TransactionList
import { getComponent } from '@MOCKS/Components';
import AccountStore from '@/store/Account';
import TransactionStore from '@/store/Transaction';
import AddressBookStore from '@/store/AddressBook';
import { getTestAccount } from '@MOCKS/Accounts';
let wrapper;
let vm;
import { addressBookMock } from '@MOCKS/AddressBookMock';
const currentSigner = getTestAccount('remoteTestnet');
const isBlackListFilterActivated = false;

beforeEach(() => {
wrapper = getComponent(
TransactionListFilters,
{ account: AccountStore, transaction: TransactionStore },
{ currentAccount: null, currentAccountSigner: {}, signers: [] },
{ account: AccountStore, transaction: TransactionStore, addressBook: AddressBookStore },
{
currentAccount: null,
currentAccountSigner: currentSigner,
addressBook: addressBookMock,
isBlackListFilterActivated: isBlackListFilterActivated,
signers: [],
},
{},
{},
);
Expand All @@ -25,8 +37,44 @@ describe('TransactionListFilters', () => {
vm.onSignerSelectorChange('TAD5BAHLOIXCRRB6GU2H72HPXMBBVAEUQRYPHBY');
expect(vm.$store.dispatch).toBeCalledWith('account/SET_CURRENT_SIGNER', { address: addr, reset: true, unsubscribeWS: false });
});

test("should not call the 'account/SET_CURRENT_SIGNER' without address", () => {
vm.onSignerSelectorChange();
expect(vm.$store.dispatch).not.toBeCalled();
});

test("should call 'transaction/filterTransactions' with blacklisted contacts", () => {

Choose a reason for hiding this comment

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

would be good to add a test when isBlackListFilterActivated == true to cover else branch too

vm.onSelectBlackListed();
expect(vm.$store.commit).toBeCalledWith('transaction/filterTransactions', {
filterOption: null,
currentSignerAddress: currentSigner.address.plain(),
multisigAddresses: [],
shouldFilterOptionChange: false,
blacklistedContacts: addressBookMock.getBlackListedContacts(),
});
expect(vm.$store.commit).toBeCalledWith('transaction/isBlackListFilterActivated', !isBlackListFilterActivated);
});

test("should call 'transaction/filterTransactions'", () => {
wrapper = getComponent(
TransactionListFilters,
{ account: AccountStore, transaction: TransactionStore, addressBook: AddressBookStore },
{
currentAccount: null,
currentAccountSigner: currentSigner,
addressBook: addressBookMock,
isBlackListFilterActivated: true,
signers: [],
},
{},
{},
);
vm = wrapper.vm as TransactionListFilters;
vm.onSelectBlackListed();
expect(vm.$store.commit).toBeCalledWith('transaction/filterTransactions', {
currentSignerAddress: currentSigner.address.plain(),
filterOption: null,
});
expect(vm.$store.commit).toBeCalledWith('transaction/isBlackListFilterActivated', false);
});
});
2 changes: 1 addition & 1 deletion __tests__/database/storage/ProfileModelStorage.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (C) Symbol Contributors 2021 Foundation
Copy link
Member

Choose a reason for hiding this comment

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

😂

* (C) Symbol Contributors 2021
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
32 changes: 32 additions & 0 deletions __tests__/language/i18n.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* (C) Symbol Contributors 2022
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and limitations under the License.
*
*/
import i18n from '@/language';

describe('language/i18n', () => {
describe("Should translations match default locale's keys", () => {
const languages = Object.keys(i18n.messages);
const defaultLanguage = i18n.locale;
const defaultLanguageLocaleKeys = Object.keys(i18n.messages[defaultLanguage]).sort();

languages.forEach((lang) => {
test(`Should keys of "${lang}" match "${defaultLanguage}"`, () => {
const locale = i18n.messages[lang];
const localeKeys = Object.keys(locale).sort();
expect(localeKeys).toEqual(defaultLanguageLocaleKeys);
});
});
});
});
34 changes: 29 additions & 5 deletions __tests__/services/TransactionFilterService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@ import { TransactionFilterOptionsState, TransactionState } from '@/store/Transac
import { TransactionFilterService } from '@/services/TransactionFilterService';
import { getTestAccount } from '@MOCKS/Accounts';
import { TransferTransaction } from 'symbol-sdk';
import { addressBookMock } from '@MOCKS/AddressBookMock';
import { IContact } from 'symbol-address-book';

const currentSigner = getTestAccount('remoteTestnet');
const recepient = getTestAccount('remoteTestnetRecipient');
const recipient = getTestAccount('remoteTestnetRecipient');
const sentTransaction = {
signer: currentSigner,
recipientAddress: {
address: currentSigner.address.plain(),
},
};
const receivedTransaction = {
signer: recepient,
signer: recipient,
recipientAddress: {
address: currentSigner.address.plain(),
address: recipient.address.plain(),
},
};

Expand All @@ -43,12 +45,13 @@ const transactionState: TransactionState = {
partialTransactions: [],
filterOptions: new TransactionFilterOptionsState(),
currentConfirmedPage: { pageNumber: 1, isLastPage: false },
isBlackListFilterActivated: false,
};

describe('services/TransactionFilterService', () => {
describe('filter()', () => {
test('should return all with all selected/unselected', async (done) => {
const result = TransactionFilterService.filter(transactionState, currentSigner.address.plain());
const result = TransactionFilterService.filter(transactionState, currentSigner.address.plain(), undefined);

transactionState.filterOptions.isSentSelected = true;
transactionState.filterOptions.isUnconfirmedSelected = true;
Expand Down Expand Up @@ -103,7 +106,28 @@ describe('services/TransactionFilterService', () => {
transactionState.filterOptions.isReceivedSelected = true;
const result = TransactionFilterService.filter(transactionState, currentSigner.address.plain());

expect(result.length).toBe(2);
expect(result.length).toBe(1);
done();
});

test('should return transactions only received from blacklisted contacts', async (done) => {
const addressBook = addressBookMock;
const contact1: IContact = {
id: '5c9093c7-2da2-476e-bc28-87f24a83cd23',
address: recipient.address.plain(),
name: 'BlackListed',
phone: '+34 000000000',
isBlackListed: true,
};
addressBook.addContact(contact1);
transactionState.filterOptions = new TransactionFilterOptionsState();
transactionState.filterOptions.isReceivedSelected = true;
const result = TransactionFilterService.filter(
transactionState,
currentSigner.address.plain(),
addressBook.getBlackListedContacts(),
);
expect(result.length).toBe(1);
done();
});

Expand Down
11 changes: 11 additions & 0 deletions __tests__/utils/CommonHelpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,15 @@ describe('utils/CommonHelpers', () => {
expect(addresses.length).toBe(2);
});
});

describe('truncate(address)', () => {
test('returns truncated string', () => {
const address = Address.createFromRawAddress('TAD5BAHLOIXCRRB6GU2H72HPXMBBVAEUQRYPHBY');
const truncatedAddress = CommonHelpers.truncate(address.plain());
const string = 'shortString';
expect(truncatedAddress.length).toBe(15);
expect(truncatedAddress.substring(truncatedAddress.length - 6)).toEqual('...HBY');
expect(CommonHelpers.truncate(string).length).toBe(11);
});
});
});
Loading