Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ def get_asset_label_index(self, asset: Asset, label: String) -> UInt64:

@subroutine
def _add_label_to_asset(self, label: String, asset: Asset) -> None:
ensure(not asset_is_deleted(asset.id), S("ERR:NOEXIST"))
ensure(label in self.labels, S("ERR:NOEXIST"))
if asset in self.assets:
# existing operator, check for duplicate
Expand Down
38 changes: 38 additions & 0 deletions projects/asset_labeling-contracts/tests/asset-labeling.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -699,4 +699,42 @@ describe('asset labeling contract', () => {

await expect(() => removeLabelFromAsset(operatorClient, assetId, label2)).rejects.toThrow(/ERR:NOEXIST/)
})

test('add label to deleted asset should fail', async () => {
const { testAccount: adminAccount, algorand } = localnet.context

const {assetId} = await algorand.send.assetCreate({
sender: adminAccount.addr,
total: 1000000n, // Total units of the asset
decimals: 0, // Number of decimals for the asset
defaultFrozen: false, // Whether the asset is frozen by default
manager: adminAccount.addr, // Address for the asset manager
reserve: adminAccount.addr, // Address for storing reserve assets
freeze: adminAccount.addr, // Address with freezing capabilities
clawback: adminAccount.addr, // Address with clawback rights
unitName: 'UNIT', // Unit name of the asset
assetName: 'TestAsset', // Asset name
})
await algorand.send.assetDestroy({
sender: adminAccount.addr,
assetId
})


const { adminClient } = await deploy(adminAccount)
const label = 'wo'
const labelName = 'world'
const labelUrl = 'http://'


await addLabel(adminClient, adminAccount, label, labelName, labelUrl)
const operator = await localnet.context.generateAccount({ initialFunds: (0.2).algos() })
await addOperatorToLabel(adminClient, operator, label)
const operatorClient = adminClient.clone({
defaultSender: operator,
defaultSigner: operator.signer,
})
// This should throw
await expect(()=>addLabelToAsset(operatorClient, assetId, label)).rejects.toThrow(/ERR:NOEXIST/)
})
})
3 changes: 2 additions & 1 deletion projects/asset_labeling-contracts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
"noEmit": true
},
"include": ["smart_contracts/**/*.ts"],
"exclude": ["node_modules", "dist", "coverage"]
"exclude": ["node_modules", "dist", "coverage"],
"references": [{"path": "./tsconfig.test.json"}]
}
7 changes: 7 additions & 0 deletions projects/asset_labeling-contracts/tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"composite": true
},
"include": ["tests/**/*.ts", "smart_contracts/artifacts/**/*.ts"]
}