Skip to content

Commit

Permalink
Built test cases and updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
yanukadeneth99 committed Oct 23, 2022
1 parent 21644ac commit 4c51638
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 24 deletions.
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,31 @@ By default, this makes the blockchain the best place to keep deeds.

## 🤖 Code

When the house is not listed for sale :

![Code_Screenshot](https://i.imgur.com/gZZ1ASv.png)

When the house is listed for sale :

![Code_Screenshot](https://i.imgur.com/ULqAr9x.png)

### 👀 Perks

- Cannot access House Information like Images, Count of Bedrooms when the house is not for sale.
- Basic Checks before listing and unlisting data.
- Error Handling and checking to make sure information is posted and rooms cannot be zero

![Code_Screenshot](https://i.imgur.com/xcWAHWr.png)
![Code_Screenshot](https://i.imgur.com/qorZdlx.png)

### Test Status

![Result_Screenshot](https://i.imgur.com/glsxteZ.png)

## 👨‍🔧 Project Plan

- [x] Finalize the Idea
- [x] Build the Contract(s)
- [x] Build the Contract
- [x] Build Test Cases
- [ ] Build a Frontend Application

## 🤝 License
Expand Down
7 changes: 7 additions & 0 deletions contracts/deed.clar
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
(asserts! (not (is-eq images "")) err-invalid-variable)
(asserts! (not (is-eq name "")) err-invalid-variable)
(map-set deeds next-deed-id {owner: tx-sender, name: name, images: images, bedroom: bedroom, bathroom: bathroom, sizeX: sizeX, sizeY: sizeY, price: u0, listed: false })
(var-set last-deed-id next-deed-id)
(ok true)
)
)
Expand Down Expand Up @@ -236,3 +237,9 @@
(define-read-only (get-owner (deed-id uint))
(ok (unwrap! (get owner (map-get? deeds deed-id)) err-deed-does-not-exist))
)

;;* Gets the last Deed ID created
;; @returns uint The Last DEED ID
(define-read-only (get-last-deed-id)
(ok (var-get last-deed-id))
)
115 changes: 93 additions & 22 deletions tests/deed_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,6 @@ Clarinet.test({

//* Stats to Run the test
const contractName = "deed";

const defaultStxVaultAmount = 5000;
const defaultMembers = [
"deployer",
"wallet_1",
"wallet_2",
"wallet_3",
"wallet_4",
];

/*
- Error List -
Expand Down Expand Up @@ -140,6 +130,8 @@ Clarinet.test({
[types.uint(1)],
deployer.address
),
// Get Last Deed ID
Tx.contractCall(contractName, "get-last-deed-id", [], deployer.address),
]);

// Transfer Should Fail
Expand All @@ -164,6 +156,8 @@ Clarinet.test({
block.receipts[9].result.expectErr().expectUint(102);
// Getting Deed
block.receipts[10].result.expectErr().expectUint(102);
// Getting Last Deed ID
block.receipts[11].result.expectOk().expectUint(0);
},
});

Expand All @@ -174,7 +168,7 @@ Clarinet.test({
let deployer = accounts.get("deployer")!;

let block = chain.mineBlock([
// Create a Deeds Incorrectly
// Name cannot be null
Tx.contractCall(
contractName,
"create-deed",
Expand All @@ -188,6 +182,7 @@ Clarinet.test({
],
deployer.address
),
// Image URL cannot be null
Tx.contractCall(
contractName,
"create-deed",
Expand All @@ -201,6 +196,7 @@ Clarinet.test({
],
deployer.address
),
// Bedroom count cannot be zero
Tx.contractCall(
contractName,
"create-deed",
Expand All @@ -214,6 +210,7 @@ Clarinet.test({
],
deployer.address
),
// Bathroom Count cannot be zero
Tx.contractCall(
contractName,
"create-deed",
Expand All @@ -227,6 +224,7 @@ Clarinet.test({
],
deployer.address
),
// Size cannot be zero
Tx.contractCall(
contractName,
"create-deed",
Expand All @@ -240,6 +238,7 @@ Clarinet.test({
],
deployer.address
),
// Size cannot be zero
Tx.contractCall(
contractName,
"create-deed",
Expand All @@ -253,6 +252,8 @@ Clarinet.test({
],
deployer.address
),
// Deed Count should be zero
Tx.contractCall(contractName, "get-last-deed-id", [], deployer.address),
// Valid Transaction
Tx.contractCall(
contractName,
Expand All @@ -267,6 +268,8 @@ Clarinet.test({
],
deployer.address
),
// Deed Count should be one
Tx.contractCall(contractName, "get-last-deed-id", [], deployer.address),
]);

// Incorrect Ones
Expand All @@ -276,9 +279,11 @@ Clarinet.test({
block.receipts[3].result.expectErr().expectUint(104);
block.receipts[4].result.expectErr().expectUint(104);
block.receipts[5].result.expectErr().expectUint(104);
block.receipts[6].result.expectOk().expectUint(0);

// Correct one
block.receipts[6].result.expectOk();
block.receipts[7].result.expectOk();
block.receipts[8].result.expectOk().expectUint(1);
},
});

Expand All @@ -303,12 +308,15 @@ Clarinet.test({
],
deployer.address
),
// Getting the 1st Deed
Tx.contractCall(
contractName,
"get-deed",
[types.uint(1)],
deployer.address
),
// Deed count must be 1
Tx.contractCall(contractName, "get-last-deed-id", [], deployer.address),
// Changing Price
Tx.contractCall(
contractName,
Expand Down Expand Up @@ -337,36 +345,44 @@ Clarinet.test({
[types.uint(1), types.uint(4)],
deployer.address
),
// Changing Bathroom Count
Tx.contractCall(
contractName,
"change-bathroom",
[types.uint(1), types.uint(2)],
deployer.address
),
// Changing Size
Tx.contractCall(
contractName,
"change-size",
[types.uint(1), types.uint(200), types.uint(200)],
deployer.address
),
// Deed count still must be 1
Tx.contractCall(contractName, "get-last-deed-id", [], deployer.address),
]);

// Created Deed
block.receipts[0].result.expectOk();
// Getting Deed by ID
block.receipts[1].result.expectOk().expectTuple();
// Deed Count must be one
block.receipts[2].result.expectOk().expectUint(1);
// Changing Price
block.receipts[2].result.expectOk();
// Changing Image URL
block.receipts[3].result.expectOk();
// Changing Name
// Changing Image URL
block.receipts[4].result.expectOk();
// Changing Bedroom count
// Changing Name
block.receipts[5].result.expectOk();
// Changing Bathroom count
// Changing Bedroom count
block.receipts[6].result.expectOk();
// Changing Size
// Changing Bathroom count
block.receipts[7].result.expectOk();
// Changing Size
block.receipts[8].result.expectOk();
// Deed Count still must be one
block.receipts[9].result.expectOk().expectUint(1);
},
});

Expand All @@ -392,6 +408,8 @@ Clarinet.test({
],
deployer.address
),
// Deed Count must be one
Tx.contractCall(contractName, "get-last-deed-id", [], deployer.address),
// Listing House for Sale
Tx.contractCall(
contractName,
Expand All @@ -402,6 +420,7 @@ Clarinet.test({
],
deployer.address
),
// Owner Must be seller
Tx.contractCall(
contractName,
"get-owner",
Expand All @@ -412,6 +431,7 @@ Clarinet.test({
),
// Buying Deed
Tx.contractCall(contractName, "buy-deed", [types.uint(1)], buyer.address),
// Owner must be buyer
Tx.contractCall(
contractName,
"get-owner",
Expand All @@ -424,22 +444,73 @@ Clarinet.test({

// Created Deed
block.receipts[0].result.expectOk();
// Deed Count must be one
block.receipts[1].result.expectOk().expectUint(1);
// Listing Deed
block.receipts[1].result.expectOk();
block.receipts[2].result.expectOk();
// Checking Address before transfer
block.receipts[2].result.expectOk().expectPrincipal(deployer.address);
block.receipts[3].result.expectOk().expectPrincipal(deployer.address);
// Buying Deed
block.receipts[3].events.expectSTXTransferEvent(
block.receipts[4].events.expectSTXTransferEvent(
1200,
buyer.address,
deployer.address
);
// Confirming Address after transfer
block.receipts[4].result.expectOk().expectPrincipal(buyer.address);
block.receipts[5].result.expectOk().expectPrincipal(buyer.address);
},
});

//* Trying to change information on an unowned deed
Clarinet.test({
name: "Non owner trying to change data",
async fn(chain: Chain, accounts: Map<string, Account>) {
let deployer = accounts.get("deployer")!;
let buyer = accounts.get("wallet_1")!;

let block = chain.mineBlock([
// Valid Transaction
Tx.contractCall(
contractName,
"create-deed",
[
types.ascii("House"), // Name
types.ascii("https://google.com"), // Image URL
types.uint(1), // Bedroom
types.uint(2), // Bathroom
types.uint(500), // Size X
types.uint(500), // Size Y
],
deployer.address
),
Tx.contractCall(
contractName,
"get-owner",
[
types.uint(1), // ID
],
deployer.address
),
// Access another person access
Tx.contractCall(
contractName,
"change-price",
[
types.uint(1), // ID
types.uint(500), // Price
],
buyer.address
),
]);

// Created Deed
block.receipts[0].result.expectOk();
// Checking the Owner before transfer
block.receipts[1].result.expectOk().expectPrincipal(deployer.address);
// Non-owner changing information
block.receipts[2].result.expectErr().expectUint(105);
},
});

//* Transferring Deed
Clarinet.test({
Expand Down

0 comments on commit 4c51638

Please sign in to comment.