Skip to content

Commit

Permalink
Fix/transfer asset permitions (#2720)
Browse files Browse the repository at this point in the history
* TransferAsset fixup!

Signed-off-by: iceseer <iceseer@gmail.com>
Signed-off-by: Alexander Lednev <57529355+iceseer@users.noreply.github.com>
  • Loading branch information
iceseer committed Sep 8, 2022
1 parent 6a20ef8 commit 5817535
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
7 changes: 3 additions & 4 deletions irohad/ametsuchi/impl/rocksdb_command_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1133,10 +1133,9 @@ RocksDbCommandExecutor::ExecutionResult RocksDbCommandExecutor::operator()(
if (opt_permissions)
granted_account_permissions = *opt_permissions;

RDB_ERROR_CHECK(checkPermissions(creator_permissions,
granted_account_permissions,
Role::kTransfer,
Grantable::kTransferMyAssets));
RDB_ERROR_CHECK(checkGrantablePermissions(creator_permissions,
granted_account_permissions,
Grantable::kTransferMyAssets));
} else
RDB_ERROR_CHECK(checkPermissions(creator_permissions, {Role::kTransfer}));

Expand Down
45 changes: 45 additions & 0 deletions test/integration/acceptance/transfer_asset_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,23 @@ struct TransferAsset : AcceptanceFixture,
.finish();
}

/**
* Creates the transaction with the third user creation commands
* @param perms are the permissions of the user
* @return built tx
*/
auto makeThirdUser(const interface::RolePermissionSet &perms = {
interface::permissions::Role::kTransfer}) {
return createUserWithPerms(
kUser3,
PublicKeyHexStringView{kUser3Keypair.publicKey()},
kRole3,
perms)
.build()
.signAndAddSignature(kAdminKeypair)
.finish();
}

proto::Transaction addAssets() {
return addAssets(kAmount);
}
Expand All @@ -73,20 +90,34 @@ struct TransferAsset : AcceptanceFixture,
baseTx().transferAsset(kUserId, kUser2Id, kAssetId, kDesc, amount));
}

proto::Transaction makeTransfer2(const std::string &amount) {
return complete(
baseTx(kUser3Id).transferAsset(kUserId, kUser2Id, kAssetId, kDesc, amount), kUser3Keypair);
}

proto::Transaction makeTransfer() {
return makeTransfer(kAmount);
}

proto::Transaction makeTransfer2() {
return makeTransfer2(kAmount);
}

static constexpr iroha::StorageType storage_types[] = {
iroha::StorageType::kPostgres, iroha::StorageType::kRocksDb};

const std::string kAmount = "1.0";
const std::string kDesc = "description";
const std::string kRole2 = "roletwo";
const std::string kRole3 = "rolethree";
const std::string kUser2 = "usertwo";
const std::string kUser3 = "userthree";
const std::string kUser2Id = kUser2 + "@" + kDomain;
const std::string kUser3Id = kUser3 + "@" + kDomain;
const crypto::Keypair kUser2Keypair =
crypto::DefaultCryptoAlgorithmType::generateKeypair();
const crypto::Keypair kUser3Keypair =
crypto::DefaultCryptoAlgorithmType::generateKeypair();
};

INSTANTIATE_TEST_SUITE_P_DifferentStorageTypes(TransferAsset);
Expand Down Expand Up @@ -131,6 +162,20 @@ TEST_P(TransferAsset, WithoutCanTransfer) {
.checkBlock(CHECK_TXS_QUANTITY(0));
}

TEST_P(TransferAsset, AnotherUserTx) {
IntegrationTestFramework(1, GetParam())
.setInitialState(kAdminKeypair)
.sendTxAwait(makeFirstUser(), CHECK_TXS_QUANTITY(1))
.sendTxAwait(makeSecondUser(), CHECK_TXS_QUANTITY(1))
.sendTxAwait(makeThirdUser(), CHECK_TXS_QUANTITY(1))
.sendTxAwait(addAssets(), CHECK_TXS_QUANTITY(1))
.sendTx(makeTransfer2())
.skipProposal()
.checkVerifiedProposal(
[](auto &proposal) { ASSERT_EQ(proposal->transactions().size(), 0); })
.checkBlock(CHECK_TXS_QUANTITY(0));
}

/**
* TODO mboldyrev 18.01.2019 IR-226 convert to a SFV integration test
* (not covered by postgres_executor_test)
Expand Down

0 comments on commit 5817535

Please sign in to comment.