From f34b05d5a4c2379716b3517904b82bfe470ff45e Mon Sep 17 00:00:00 2001 From: Bjarte Stien Karlsen Date: Fri, 13 Dec 2024 10:16:24 +0100 Subject: [PATCH] fixing renew name --- find_test.go | 25 ++++++++++++++++++++----- lib/find.json | 8 ++++---- lib/package.json | 2 +- transactions/renewName.cdc | 2 +- 4 files changed, 26 insertions(+), 11 deletions(-) diff --git a/find_test.go b/find_test.go index 942a2064..18dd8ab3 100644 --- a/find_test.go +++ b/find_test.go @@ -24,12 +24,27 @@ func TestFIND(t *testing.T) { // this use does not have a profile at all user4Address := otu.O.Address("user4") - ot.Run(t, "Should get error if you try to register a name and dont have enough money", func(t *testing.T) { - otu.O.Tx("register", + ot.Run(t, "Should be able to renew lease", func(t *testing.T) { + otu.O.Tx("cleanUpInvalidatedLease", WithSigner("user1"), - WithArg("name", "usr"), - WithArg("maxAmount", 1000.0), - ).AssertFailure(t, "Balance of vault is not high enough") + WithArg("names", []string{"user1"}), + ). + AssertFailure(t, "This is a valid lease. You cannot clean this up") + + otu.expireLease().expireLease().tickClock(2.0) + otu.O.Tx("cleanUpInvalidatedLease", + + WithSigner("user1"), + WithArg("names", []string{"user1"}), + ).AssertSuccess(t) + }) + + ot.Run(t, "Should be able to renew nam", func(t *testing.T) { + otu.O.Tx("renewName", + WithSigner("user1"), + WithArg("name", "user1"), + WithArg("maxAmount", 10.5), + ).AssertSuccess(t) }) ot.Run(t, "Should get error if you try to register a name that is too short", func(t *testing.T) { diff --git a/lib/find.json b/lib/find.json index 7aa7c957..68dd3c1f 100644 --- a/lib/find.json +++ b/lib/find.json @@ -2184,7 +2184,7 @@ "maxAmount" ] }, - "code": "import FlowToken from 0x0ae53cb6e3f42a79\nimport FungibleToken from 0xee82856bf20e2aa6\nimport FIND from 0xf3fcd2c1a78f5eee\n\ntransaction(name: String, maxAmount: UFix64) {\n\n let cost : UFix64\n let vaultRef : auth (FungibleToken.Withdraw) \u0026FlowToken.Vault? \n let finLeases : auth(FIND.LeaseOwner) \u0026FIND.LeaseCollection? \n\n prepare(acct: auth(BorrowValue) \u0026Account) {\n self.cost=FIND.calculateCostInFlow(name)\n self.vaultRef = acct.storage.borrow\u003cauth (FungibleToken.Withdraw) \u0026FlowToken.Vault\u003e(from: /storage/flowTokenVault)\n self.finLeases= acct.storage.borrow\u003cauth(FIND.LeaseOwner) \u0026FIND.LeaseCollection\u003e(from:FIND.LeaseStoragePath)\n }\n\n\n pre{\n self.vaultRef != nil : \"Could not borrow reference to the fusdVault!\"\n self.finLeases != nil : \"Could not borrow reference to find lease collection\"\n self.cost \u003c= maxAmount : \"You have not sent in enough max flow, the cost is \".concat(self.cost.toString())\n self.vaultRef!.balance \u003e self.cost : \"Balance of vault is not high enough \".concat(self.vaultRef!.balance.toString().concat(\" total balance is \").concat(self.vaultRef!.balance.toString()))\n }\n\n execute{\n let payVault \u003c- self.vaultRef!.withdraw(amount: self.cost) as! @FlowToken.Vault\n let finToken= self.finLeases!.borrow(name)\n finToken.extendLease(\u003c- payVault)\n }\n}" + "code": "import FlowToken from 0x0ae53cb6e3f42a79\nimport FungibleToken from 0xee82856bf20e2aa6\nimport FIND from 0xf3fcd2c1a78f5eee\n\ntransaction(name: String, maxAmount: UFix64) {\n\n let cost : UFix64\n let vaultRef : auth (FungibleToken.Withdraw) \u0026FlowToken.Vault? \n let finLeases : auth(FIND.LeaseOwner) \u0026FIND.LeaseCollection? \n\n prepare(acct: auth(BorrowValue) \u0026Account) {\n self.cost=FIND.calculateCostInFlow(name)\n self.vaultRef = acct.storage.borrow\u003cauth (FungibleToken.Withdraw) \u0026FlowToken.Vault\u003e(from: /storage/flowTokenVault)\n self.finLeases= acct.storage.borrow\u003cauth(FIND.LeaseOwner) \u0026FIND.LeaseCollection\u003e(from:FIND.LeaseStoragePath)\n }\n\n\n pre{\n self.vaultRef != nil : \"Could not borrow reference to the fusdVault!\"\n self.finLeases != nil : \"Could not borrow reference to find lease collection\"\n self.cost \u003c= maxAmount : \"You have not sent in enough max flow, the cost is \".concat(self.cost.toString())\n self.vaultRef!.balance \u003e self.cost : \"Balance of vault is not high enough \".concat(self.vaultRef!.balance.toString().concat(\" total balance is \").concat(self.vaultRef!.balance.toString()))\n }\n\n execute{\n let payVault \u003c- self.vaultRef!.withdraw(amount: self.cost) as! @FlowToken.Vault\n let finToken= self.finLeases!.borrowAuth(name)\n finToken.extendLease(\u003c- payVault)\n }\n}" }, "retractOfferLeaseMarketDirectOfferSoft": { "spec": { @@ -4911,7 +4911,7 @@ "maxAmount" ] }, - "code": "import FlowToken from 0x1654653399040a61\nimport FungibleToken from 0xf233dcee88fe0abe\nimport FIND from 0x097bafa4e0b48eef\n\ntransaction(name: String, maxAmount: UFix64) {\n\n let cost : UFix64\n let vaultRef : auth (FungibleToken.Withdraw) \u0026FlowToken.Vault? \n let finLeases : auth(FIND.LeaseOwner) \u0026FIND.LeaseCollection? \n\n prepare(acct: auth(BorrowValue) \u0026Account) {\n self.cost=FIND.calculateCostInFlow(name)\n self.vaultRef = acct.storage.borrow\u003cauth (FungibleToken.Withdraw) \u0026FlowToken.Vault\u003e(from: /storage/flowTokenVault)\n self.finLeases= acct.storage.borrow\u003cauth(FIND.LeaseOwner) \u0026FIND.LeaseCollection\u003e(from:FIND.LeaseStoragePath)\n }\n\n\n pre{\n self.vaultRef != nil : \"Could not borrow reference to the fusdVault!\"\n self.finLeases != nil : \"Could not borrow reference to find lease collection\"\n self.cost \u003c= maxAmount : \"You have not sent in enough max flow, the cost is \".concat(self.cost.toString())\n self.vaultRef!.balance \u003e self.cost : \"Balance of vault is not high enough \".concat(self.vaultRef!.balance.toString().concat(\" total balance is \").concat(self.vaultRef!.balance.toString()))\n }\n\n execute{\n let payVault \u003c- self.vaultRef!.withdraw(amount: self.cost) as! @FlowToken.Vault\n let finToken= self.finLeases!.borrow(name)\n finToken.extendLease(\u003c- payVault)\n }\n}" + "code": "import FlowToken from 0x1654653399040a61\nimport FungibleToken from 0xf233dcee88fe0abe\nimport FIND from 0x097bafa4e0b48eef\n\ntransaction(name: String, maxAmount: UFix64) {\n\n let cost : UFix64\n let vaultRef : auth (FungibleToken.Withdraw) \u0026FlowToken.Vault? \n let finLeases : auth(FIND.LeaseOwner) \u0026FIND.LeaseCollection? \n\n prepare(acct: auth(BorrowValue) \u0026Account) {\n self.cost=FIND.calculateCostInFlow(name)\n self.vaultRef = acct.storage.borrow\u003cauth (FungibleToken.Withdraw) \u0026FlowToken.Vault\u003e(from: /storage/flowTokenVault)\n self.finLeases= acct.storage.borrow\u003cauth(FIND.LeaseOwner) \u0026FIND.LeaseCollection\u003e(from:FIND.LeaseStoragePath)\n }\n\n\n pre{\n self.vaultRef != nil : \"Could not borrow reference to the fusdVault!\"\n self.finLeases != nil : \"Could not borrow reference to find lease collection\"\n self.cost \u003c= maxAmount : \"You have not sent in enough max flow, the cost is \".concat(self.cost.toString())\n self.vaultRef!.balance \u003e self.cost : \"Balance of vault is not high enough \".concat(self.vaultRef!.balance.toString().concat(\" total balance is \").concat(self.vaultRef!.balance.toString()))\n }\n\n execute{\n let payVault \u003c- self.vaultRef!.withdraw(amount: self.cost) as! @FlowToken.Vault\n let finToken= self.finLeases!.borrowAuth(name)\n finToken.extendLease(\u003c- payVault)\n }\n}" }, "renewNameDapper": { "spec": { @@ -7511,7 +7511,7 @@ "maxAmount" ] }, - "code": "import FlowToken from 0x7e60df042a9c0868\nimport FungibleToken from 0x9a0766d93b6608b7\nimport FIND from 0x35717efbbce11c74\n\ntransaction(name: String, maxAmount: UFix64) {\n\n let cost : UFix64\n let vaultRef : auth (FungibleToken.Withdraw) \u0026FlowToken.Vault? \n let finLeases : auth(FIND.LeaseOwner) \u0026FIND.LeaseCollection? \n\n prepare(acct: auth(BorrowValue) \u0026Account) {\n self.cost=FIND.calculateCostInFlow(name)\n self.vaultRef = acct.storage.borrow\u003cauth (FungibleToken.Withdraw) \u0026FlowToken.Vault\u003e(from: /storage/flowTokenVault)\n self.finLeases= acct.storage.borrow\u003cauth(FIND.LeaseOwner) \u0026FIND.LeaseCollection\u003e(from:FIND.LeaseStoragePath)\n }\n\n\n pre{\n self.vaultRef != nil : \"Could not borrow reference to the fusdVault!\"\n self.finLeases != nil : \"Could not borrow reference to find lease collection\"\n self.cost \u003c= maxAmount : \"You have not sent in enough max flow, the cost is \".concat(self.cost.toString())\n self.vaultRef!.balance \u003e self.cost : \"Balance of vault is not high enough \".concat(self.vaultRef!.balance.toString().concat(\" total balance is \").concat(self.vaultRef!.balance.toString()))\n }\n\n execute{\n let payVault \u003c- self.vaultRef!.withdraw(amount: self.cost) as! @FlowToken.Vault\n let finToken= self.finLeases!.borrow(name)\n finToken.extendLease(\u003c- payVault)\n }\n}" + "code": "import FlowToken from 0x7e60df042a9c0868\nimport FungibleToken from 0x9a0766d93b6608b7\nimport FIND from 0x35717efbbce11c74\n\ntransaction(name: String, maxAmount: UFix64) {\n\n let cost : UFix64\n let vaultRef : auth (FungibleToken.Withdraw) \u0026FlowToken.Vault? \n let finLeases : auth(FIND.LeaseOwner) \u0026FIND.LeaseCollection? \n\n prepare(acct: auth(BorrowValue) \u0026Account) {\n self.cost=FIND.calculateCostInFlow(name)\n self.vaultRef = acct.storage.borrow\u003cauth (FungibleToken.Withdraw) \u0026FlowToken.Vault\u003e(from: /storage/flowTokenVault)\n self.finLeases= acct.storage.borrow\u003cauth(FIND.LeaseOwner) \u0026FIND.LeaseCollection\u003e(from:FIND.LeaseStoragePath)\n }\n\n\n pre{\n self.vaultRef != nil : \"Could not borrow reference to the fusdVault!\"\n self.finLeases != nil : \"Could not borrow reference to find lease collection\"\n self.cost \u003c= maxAmount : \"You have not sent in enough max flow, the cost is \".concat(self.cost.toString())\n self.vaultRef!.balance \u003e self.cost : \"Balance of vault is not high enough \".concat(self.vaultRef!.balance.toString().concat(\" total balance is \").concat(self.vaultRef!.balance.toString()))\n }\n\n execute{\n let payVault \u003c- self.vaultRef!.withdraw(amount: self.cost) as! @FlowToken.Vault\n let finToken= self.finLeases!.borrowAuth(name)\n finToken.extendLease(\u003c- payVault)\n }\n}" }, "retractOfferLeaseMarketDirectOfferSoft": { "spec": { @@ -10292,7 +10292,7 @@ "maxAmount" ] }, - "code": "import FlowToken from 0x7e60df042a9c0868\nimport FungibleToken from 0x9a0766d93b6608b7\nimport FIND from 0x35717efbbce11c74\n\ntransaction(name: String, maxAmount: UFix64) {\n\n let cost : UFix64\n let vaultRef : auth (FungibleToken.Withdraw) \u0026FlowToken.Vault? \n let finLeases : auth(FIND.LeaseOwner) \u0026FIND.LeaseCollection? \n\n prepare(acct: auth(BorrowValue) \u0026Account) {\n self.cost=FIND.calculateCostInFlow(name)\n self.vaultRef = acct.storage.borrow\u003cauth (FungibleToken.Withdraw) \u0026FlowToken.Vault\u003e(from: /storage/flowTokenVault)\n self.finLeases= acct.storage.borrow\u003cauth(FIND.LeaseOwner) \u0026FIND.LeaseCollection\u003e(from:FIND.LeaseStoragePath)\n }\n\n\n pre{\n self.vaultRef != nil : \"Could not borrow reference to the fusdVault!\"\n self.finLeases != nil : \"Could not borrow reference to find lease collection\"\n self.cost \u003c= maxAmount : \"You have not sent in enough max flow, the cost is \".concat(self.cost.toString())\n self.vaultRef!.balance \u003e self.cost : \"Balance of vault is not high enough \".concat(self.vaultRef!.balance.toString().concat(\" total balance is \").concat(self.vaultRef!.balance.toString()))\n }\n\n execute{\n let payVault \u003c- self.vaultRef!.withdraw(amount: self.cost) as! @FlowToken.Vault\n let finToken= self.finLeases!.borrow(name)\n finToken.extendLease(\u003c- payVault)\n }\n}" + "code": "import FlowToken from 0x7e60df042a9c0868\nimport FungibleToken from 0x9a0766d93b6608b7\nimport FIND from 0x35717efbbce11c74\n\ntransaction(name: String, maxAmount: UFix64) {\n\n let cost : UFix64\n let vaultRef : auth (FungibleToken.Withdraw) \u0026FlowToken.Vault? \n let finLeases : auth(FIND.LeaseOwner) \u0026FIND.LeaseCollection? \n\n prepare(acct: auth(BorrowValue) \u0026Account) {\n self.cost=FIND.calculateCostInFlow(name)\n self.vaultRef = acct.storage.borrow\u003cauth (FungibleToken.Withdraw) \u0026FlowToken.Vault\u003e(from: /storage/flowTokenVault)\n self.finLeases= acct.storage.borrow\u003cauth(FIND.LeaseOwner) \u0026FIND.LeaseCollection\u003e(from:FIND.LeaseStoragePath)\n }\n\n\n pre{\n self.vaultRef != nil : \"Could not borrow reference to the fusdVault!\"\n self.finLeases != nil : \"Could not borrow reference to find lease collection\"\n self.cost \u003c= maxAmount : \"You have not sent in enough max flow, the cost is \".concat(self.cost.toString())\n self.vaultRef!.balance \u003e self.cost : \"Balance of vault is not high enough \".concat(self.vaultRef!.balance.toString().concat(\" total balance is \").concat(self.vaultRef!.balance.toString()))\n }\n\n execute{\n let payVault \u003c- self.vaultRef!.withdraw(amount: self.cost) as! @FlowToken.Vault\n let finToken= self.finLeases!.borrowAuth(name)\n finToken.extendLease(\u003c- payVault)\n }\n}" }, "renewNameDapper": { "spec": { diff --git a/lib/package.json b/lib/package.json index b47a45fa..70d06efa 100644 --- a/lib/package.json +++ b/lib/package.json @@ -1,6 +1,6 @@ { "name": "@findonflow/find-flow-contracts-1.0", - "version": "1.2.2", + "version": "1.2.3", "description": "Cadence transactions and scripts to work with https://find.xyz for cadence 1.0", "main": "index.js", "scripts": { diff --git a/transactions/renewName.cdc b/transactions/renewName.cdc index e3c0dba0..3ea97cff 100644 --- a/transactions/renewName.cdc +++ b/transactions/renewName.cdc @@ -24,7 +24,7 @@ transaction(name: String, maxAmount: UFix64) { execute{ let payVault <- self.vaultRef!.withdraw(amount: self.cost) as! @FlowToken.Vault - let finToken= self.finLeases!.borrow(name) + let finToken= self.finLeases!.borrowAuth(name) finToken.extendLease(<- payVault) } }