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

Revert "Fix SIP-010 implementation" #55

Closed
wants to merge 1 commit into from
Closed
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
22 changes: 9 additions & 13 deletions contracts/citycoin.clar
Original file line number Diff line number Diff line change
Expand Up @@ -855,13 +855,9 @@
))
)

(define-read-only (get-total-supply-ustx)
(ok (stx-get-balance (as-contract tx-sender)))
)

;;;;;;;;;;;;;;;;;;;;; SIP 010 ;;;;;;;;;;;;;;;;;;;;;;
;; testnet implementation
;; (impl-trait 'STR8P3RD1EHA8AA37ERSSSZSWKS9T2GYQFGXNA4C.sip-010-trait.sip-010-trait)
;; (impl-trait 'ST1HTBVD3JG9C05J7HBJTHGR0GGW7KXW28M5JS8QE.sip-010-trait.sip-010-trait)
(impl-trait 'SP3FBR2AGK5H9QBDH3EEN6DF8EK8JY7RX8QJ5SVTE.sip-010-trait.sip-010-trait)

(define-public (transfer (amount uint) (from principal) (to principal) (memo (optional (buff 34))))
Expand All @@ -873,20 +869,20 @@
)
)

(define-read-only (name)
(define-public (get-name)
(ok "citycoins"))

(define-read-only (symbol)
(define-public (get-symbol)
(ok "CYCN"))

(define-read-only (decimals)
(define-public (get-decimals)
(ok u0))

(define-read-only (balance-of (user principal))
(define-public (get-balance-of (user principal))
(ok (ft-get-balance citycoins user)))

(define-read-only (total-supply)
(ok (ft-get-supply citycoins)))
(define-public (get-total-supply)
(ok (stx-get-balance (as-contract tx-sender))))

(define-read-only (get-token-uri)
(ok (some u"https://cdn.citycoins.co/metadata/citycoin.json")))
(define-public (get-token-uri)
(ok none))
10 changes: 5 additions & 5 deletions contracts/sip-10-ft-standard.clar
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
(transfer (uint principal principal (optional (buff 34))) (response bool uint))

;; the human readable name of the token
(name () (response (string-ascii 32) uint))
(get-name () (response (string-ascii 32) uint))

;; the ticker symbol, or empty if none
(symbol () (response (string-ascii 32) uint))
(get-symbol () (response (string-ascii 32) uint))

;; the number of decimals used, e.g. 6 would mean 1_000_000 represents 1 token
(decimals () (response uint uint))
(get-decimals () (response uint uint))

;; the balance of the passed principal
(balance-of (principal) (response uint uint))
(get-balance-of (principal) (response uint uint))

;; the current total supply (which does not need to be a constant)
(total-supply () (response uint uint))
(get-total-supply () (response uint uint))

;; an optional URI that represents metadata of this token
(get-token-uri () (response (optional (string-utf8 256)) uint))
Expand Down
14 changes: 5 additions & 9 deletions src/citycoin-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,6 @@ export class CityCoinClient {
)
}

getTotalSupplyUstx(): Result {
return this.callReadOnlyFn("get-total-supply-ustx");
}

// SIP-010 functions

transfer(amount: number, from: Account, to: Account, sender: Account): Tx {
Expand All @@ -379,25 +375,25 @@ export class CityCoinClient {
}

getName(): Result {
return this.callReadOnlyFn("name");
return this.callReadOnlyFn("get-name");
}

getSymbol(): Result {
return this.callReadOnlyFn("symbol");
return this.callReadOnlyFn("get-symbol");
}

getDecimals(): Result {
return this.callReadOnlyFn("decimals");
return this.callReadOnlyFn("get-decimals");
}

getBalanceOf(user: Account): Result {
return this.callReadOnlyFn("balance-of", [
return this.callReadOnlyFn("get-balance-of", [
types.principal(user.address)
])
}

getTotalSupply(): Result {
return this.callReadOnlyFn("total-supply");
return this.callReadOnlyFn("get-total-supply");
}

getTokenUri(): Result {
Expand Down
81 changes: 15 additions & 66 deletions tests/citycoin_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,71 +123,8 @@ describe('[CityCoin]', () => {
setupCleanEnv();
})

it("should return 0", () => {
const result = client.getTotalSupply().result;

result.expectOk().expectUint(0);
});

it("should return 100 after 100 tokens are minted", () => {
chain.mineBlock([
client.ftMint(100, wallet_1)
]);

const result = client.getTotalSupply().result;

result.expectOk().expectUint(100);
});

it("should return 250000 after a miner wins a block", () => {
// activate mining
chain.mineBlock([
client.setMiningActivationThreshold(1),
client.registerMiner(wallet_3)
]);

// advance chain to block where mining is active
chain.mineEmptyBlock(MINING_ACTIVATION_DELAY);

// mine a block
const block = chain.mineBlock([
client.mineTokens(100, wallet_1)
]);

// advance chain past miner reward window
chain.mineEmptyBlock(101);

// claim tokens so they are minted
chain.mineBlock([
client.claimTokenReward(block.height - 1, wallet_1)
]);

const result = client.getTotalSupply().result;

result.expectOk().expectUint(250000);
});

});

describe("get-token-uri()", () => {
it("should return none", () => {
const result = client.getTokenUri().result;

result.expectOk().expectSome().expectUtf8("https://cdn.citycoins.co/metadata/citycoin.json");
});
});
});

describe("Read only functions:", () => {
setupCleanEnv();

describe("get-total-supply-ustx()", () => {
beforeEach(() => {
setupCleanEnv();
})

it("should return 0 if nobody mined", () => {
const result = client.getTotalSupplyUstx().result;
const result = client.getTotalSupply().result;

result.expectOk().expectUint(0);
});
Expand All @@ -205,7 +142,7 @@ describe('[CityCoin]', () => {
client.mineTokens(100, wallet_1)
]);

const result = client.getTotalSupplyUstx().result;
const result = client.getTotalSupply().result;

result.expectOk().expectUint(0);
});
Expand Down Expand Up @@ -234,12 +171,24 @@ describe('[CityCoin]', () => {
client.mineTokens(100, wallet_1)
]);

const result = client.getTotalSupplyUstx().result;
const result = client.getTotalSupply().result;

result.expectOk().expectUint(100 * SPLIT_STACKER_PERCENTAGE);
});
});

describe("get-token-uri()", () => {
it("should return none", () => {
const result = client.getTokenUri().result;

result.expectOk().expectNone();
});
});
});

describe("Read only functions:", () => {
setupCleanEnv();

describe("get-coinbase-amount()", () => {

it("returns correct coinbase amount based on Stacks block height", () => {
Expand Down