Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into PE-6228-ant-module
Browse files Browse the repository at this point in the history
  • Loading branch information
Atticus committed Jun 14, 2024
2 parents e968fd2 + 6996cad commit 58b690e
Show file tree
Hide file tree
Showing 15 changed files with 502 additions and 229 deletions.
56 changes: 28 additions & 28 deletions contract/spec/arns_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe("arns", function()
reserved = {},
}
_G.Balances = {
["test-wallet-address-1"] = 5000000,
["test-this-is-valid-arweave-wallet-address-1"] = 5000000,
}
end)

Expand All @@ -22,7 +22,7 @@ describe("arns", function()
local demandBefore = demand.getCurrentPeriodRevenue()
local purchasesBefore = demand.getCurrentPeriodPurchases()
local status, result =
pcall(arns.buyRecord, "test-name", "lease", 1, "test-wallet-address-1", timestamp, testProcessId)
pcall(arns.buyRecord, "test-name", "lease", 1, "test-this-is-valid-arweave-wallet-address-1", timestamp, testProcessId)
assert.is_true(status)
assert.are.same({
purchasePrice = 1500,
Expand All @@ -42,7 +42,7 @@ describe("arns", function()
endTimestamp = timestamp + constants.oneYearMs * 1,
},
}, arns.getRecords())
assert.are.equal(balances.getBalance("test-wallet-address-1"), 4998500)
assert.are.equal(balances.getBalance("test-this-is-valid-arweave-wallet-address-1"), 4998500)
assert.are.equal(balances.getBalance(_G.ao.id), 1500)
assert.are.equal(demandBefore + 1500, demand.getCurrentPeriodRevenue())
assert.are.equal(purchasesBefore + 1, demand.getCurrentPeriodPurchases())
Expand All @@ -52,7 +52,7 @@ describe("arns", function()
local demandBefore = demand.getCurrentPeriodRevenue()
local purchasesBefore = demand.getCurrentPeriodPurchases()
local status, result =
pcall(arns.buyRecord, "test-name", nil, nil, "test-wallet-address-1", timestamp, testProcessId)
pcall(arns.buyRecord, "test-name", nil, nil, "test-this-is-valid-arweave-wallet-address-1", timestamp, testProcessId)
assert.is_true(status)
assert.are.same({
purchasePrice = 1500,
Expand All @@ -71,7 +71,7 @@ describe("arns", function()
endTimestamp = timestamp + constants.oneYearMs,
}, arns.getRecord("test-name"))
assert.are.same({
["test-wallet-address-1"] = 4998500,
["test-this-is-valid-arweave-wallet-address-1"] = 4998500,
[_G.ao.id] = 1500,
}, balances.getBalances())
assert.are.equal(demandBefore + 1500, demand.getCurrentPeriodRevenue())
Expand All @@ -84,7 +84,7 @@ describe("arns", function()
"test-name",
"lease",
constants.maxLeaseLengthYears + 1,
"test-wallet-address-1",
"test-this-is-valid-arweave-wallet-address-1",
timestamp,
testProcessId
)
Expand All @@ -103,7 +103,7 @@ describe("arns", function()
}
NameRegistry.records["test-name"] = existingRecord
local status, result =
pcall(arns.buyRecord, "test-name", "lease", 1, "test-wallet-address-1", timestamp, testProcessId)
pcall(arns.buyRecord, "test-name", "lease", 1, "test-this-is-valid-arweave-wallet-address-1", timestamp, testProcessId)
assert.is_false(status)
assert.match("Name is already registered", result)
assert.are.same(existingRecord, NameRegistry.records["test-name"])
Expand All @@ -116,7 +116,7 @@ describe("arns", function()
}
NameRegistry.reserved["test-name"] = reservedName
local status, result =
pcall(arns.buyRecord, "test-name", "lease", 1, "test-wallet-address-1", timestamp, testProcessId)
pcall(arns.buyRecord, "test-name", "lease", 1, "test-this-is-valid-arweave-wallet-address-1", timestamp, testProcessId)
assert.is_false(status)
assert.match("Name is reserved", result)
assert.are.same({}, arns.getRecords())
Expand All @@ -127,11 +127,11 @@ describe("arns", function()
local demandBefore = demand.getCurrentPeriodRevenue()
local purchasesBefore = demand.getCurrentPeriodPurchases()
NameRegistry.reserved["test-name"] = {
target = "test-wallet-address-1",
target = "test-this-is-valid-arweave-wallet-address-1",
endTimestamp = 1000,
}
local status, result =
pcall(arns.buyRecord, "test-name", "lease", 1, "test-wallet-address-1", timestamp, testProcessId)
pcall(arns.buyRecord, "test-name", "lease", 1, "test-this-is-valid-arweave-wallet-address-1", timestamp, testProcessId)
local expectation = {
endTimestamp = timestamp + constants.oneYearMs,
processId = testProcessId,
Expand All @@ -144,17 +144,17 @@ describe("arns", function()
assert.are.same(expectation, result)
assert.are.same({ ["test-name"] = expectation }, arns.getRecords())
assert.are.same({
["test-wallet-address-1"] = 4998500,
["test-this-is-valid-arweave-wallet-address-1"] = 4998500,
[_G.ao.id] = 1500,
}, balances.getBalances())
assert.are.equal(demandBefore + 1500, demand.getCurrentPeriodRevenue())
assert.are.equal(purchasesBefore + 1, demand.getCurrentPeriodPurchases())
end)

it("should throw an error if the user does not have enough balance", function()
Balances["test-wallet-address-1"] = 0
Balances["test-this-is-valid-arweave-wallet-address-1"] = 0
local status, result =
pcall(arns.buyRecord, "test-name", "lease", 1, "test-wallet-address-1", timestamp, testProcessId)
pcall(arns.buyRecord, "test-name", "lease", 1, "test-this-is-valid-arweave-wallet-address-1", timestamp, testProcessId)
assert.is_false(status)
assert.match("Insufficient balance", result)
assert.are.same({}, arns.getRecords())
Expand All @@ -164,7 +164,7 @@ describe("arns", function()
describe("increaseUndernameCount", function()
it("should throw an error if name is not active", function()
local status, error =
pcall(arns.increaseUndernameCount, "test-wallet-address-1", "test-name", 50, timestamp)
pcall(arns.increaseUndernameCount, "test-this-is-valid-arweave-wallet-address-1", "test-name", 50, timestamp)
assert.is_false(status)
assert.match("Name is not registered", error)
end)
Expand All @@ -179,9 +179,9 @@ describe("arns", function()
type = "lease",
undernameCount = 10,
}
Balances["test-wallet-address-1"] = 0
Balances["test-this-is-valid-arweave-wallet-address-1"] = 0
local status, error =
pcall(arns.increaseUndernameCount, "test-wallet-address-1", "test-name", 50, timestamp)
pcall(arns.increaseUndernameCount, "test-this-is-valid-arweave-wallet-address-1", "test-name", 50, timestamp)
assert.is_false(status)
assert.match("Insufficient balance", error)
end)
Expand All @@ -195,7 +195,7 @@ describe("arns", function()
type = "lease",
undernameCount = constants.MAX_ALLOWED_UNDERNAMES,
}
local status, error = pcall(arns.increaseUndernameCount, "test-wallet-address-1", "test-name", 1, timestamp)
local status, error = pcall(arns.increaseUndernameCount, "test-this-is-valid-arweave-wallet-address-1", "test-name", 1, timestamp)
assert.is_false(status)
assert.match(constants.ARNS_MAX_UNDERNAME_MESSAGE, error)
end)
Expand All @@ -211,7 +211,7 @@ describe("arns", function()
}
local status, error = pcall(
arns.increaseUndernameCount,
"test-wallet-address-1",
"test-this-is-valid-arweave-wallet-address-1",
"test-name",
1,
timestamp + constants.oneYearMs + 1
Expand All @@ -232,7 +232,7 @@ describe("arns", function()
local demandBefore = demand.getCurrentPeriodRevenue()
local purchasesBefore = demand.getCurrentPeriodPurchases()
local status, result =
pcall(arns.increaseUndernameCount, "test-wallet-address-1", "test-name", 50, timestamp)
pcall(arns.increaseUndernameCount, "test-this-is-valid-arweave-wallet-address-1", "test-name", 50, timestamp)
local expectation = {
endTimestamp = timestamp + constants.oneYearMs,
processId = testProcessId,
Expand All @@ -245,7 +245,7 @@ describe("arns", function()
assert.are.same(expectation, result)
assert.are.same({ ["test-name"] = expectation }, arns.getRecords())
assert.are.same({
["test-wallet-address-1"] = 4999937.5,
["test-this-is-valid-arweave-wallet-address-1"] = 4999937.5,
[_G.ao.id] = 62.5,
}, balances.getBalances())
assert.are.equal(demandBefore + 62.5, demand.getCurrentPeriodRevenue())
Expand All @@ -255,7 +255,7 @@ describe("arns", function()

describe("extendLease", function()
it("should throw an error if name is not active", function()
local status, error = pcall(arns.extendLease, "test-wallet-address-1", "test-name", 1)
local status, error = pcall(arns.extendLease, "test-this-is-valid-arweave-wallet-address-1", "test-name", 1)
assert.is_false(status)
assert.match("Name is not registered", error)
end)
Expand All @@ -271,7 +271,7 @@ describe("arns", function()
}
local status, error = pcall(
arns.extendLease,
"test-wallet-address-1",
"test-this-is-valid-arweave-wallet-address-1",
"test-name",
1,
timestamp + constants.oneYearMs + constants.gracePeriodMs + 1
Expand All @@ -289,7 +289,7 @@ describe("arns", function()
type = "permabuy",
undernameCount = 10,
}
local status, error = pcall(arns.extendLease, "test-wallet-address-1", "test-name", 1, timestamp)
local status, error = pcall(arns.extendLease, "test-this-is-valid-arweave-wallet-address-1", "test-name", 1, timestamp)
assert.is_false(status)
assert.match("Name is permabought and cannot be extended", error)
end)
Expand All @@ -304,8 +304,8 @@ describe("arns", function()
type = "lease",
undernameCount = 10,
}
Balances["test-wallet-address-1"] = 0
local status, error = pcall(arns.extendLease, "test-wallet-address-1", "test-name", 1, timestamp)
Balances["test-this-is-valid-arweave-wallet-address-1"] = 0
local status, error = pcall(arns.extendLease, "test-this-is-valid-arweave-wallet-address-1", "test-name", 1, timestamp)
assert.is_false(status)
assert.match("Insufficient balance", error)
end)
Expand All @@ -322,7 +322,7 @@ describe("arns", function()
}
local demandBefore = demand.getCurrentPeriodRevenue()
local purchasesBefore = demand.getCurrentPeriodPurchases()
local status, result = pcall(arns.extendLease, "test-wallet-address-1", "test-name", 4, timestamp)
local status, result = pcall(arns.extendLease, "test-this-is-valid-arweave-wallet-address-1", "test-name", 4, timestamp)
assert.is_true(status)
assert.are.same({
endTimestamp = timestamp + constants.oneYearMs * 5,
Expand All @@ -343,7 +343,7 @@ describe("arns", function()
},
}, arns.getRecords())
assert.are.same({
["test-wallet-address-1"] = 4999000,
["test-this-is-valid-arweave-wallet-address-1"] = 4999000,
[_G.ao.id] = 1000,
}, balances.getBalances())
assert.are.equal(demandBefore + 1000, demand.getCurrentPeriodRevenue())
Expand All @@ -360,7 +360,7 @@ describe("arns", function()
type = "lease",
undernameCount = 10,
}
local status, error = pcall(arns.extendLease, "test-wallet-address-1", "test-name", 6, timestamp)
local status, error = pcall(arns.extendLease, "test-this-is-valid-arweave-wallet-address-1", "test-name", 6, timestamp)
assert.is_false(status)
assert.match("Cannot extend lease beyond 5 years", error)
end)
Expand Down
18 changes: 9 additions & 9 deletions contract/spec/balances_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ local balances = require("src.balances")
describe("balances", function()
before_each(function()
_G.Balances = {
["test-wallet-address-1"] = 100,
["test-this-is-valid-arweave-wallet-address-1"] = 100,
}
end)

it("should transfer tokens", function()
local status, result = pcall(balances.transfer, "test-wallet-address-2", "test-wallet-address-1", 100)
local status, result = pcall(balances.transfer, "test-this-is-valid-arweave-wallet-address-2", "test-this-is-valid-arweave-wallet-address-1", 100)
assert.is_true(status)
assert.are.same(result["test-wallet-address-2"], balances.getBalance("test-wallet-address-2"))
assert.are.same(result["test-wallet-address-1"], balances.getBalance("test-wallet-address-1"))
assert.are.equal(100, balances.getBalance("test-wallet-address-2"))
assert.are.equal(0, balances.getBalance("test-wallet-address-1"))
assert.are.same(result["test-this-is-valid-arweave-wallet-address-2"], balances.getBalance("test-this-is-valid-arweave-wallet-address-2"))
assert.are.same(result["test-this-is-valid-arweave-wallet-address-1"], balances.getBalance("test-this-is-valid-arweave-wallet-address-1"))
assert.are.equal(100, balances.getBalance("test-this-is-valid-arweave-wallet-address-2"))
assert.are.equal(0, balances.getBalance("test-this-is-valid-arweave-wallet-address-1"))
end)

it("should error on insufficient balance", function()
local status, result = pcall(balances.transfer, "test-wallet-address-2", "test-wallet-address-1", 101)
local status, result = pcall(balances.transfer, "test-this-is-valid-arweave-wallet-address-2", "test-this-is-valid-arweave-wallet-address-1", 101)
assert.is_false(status)
assert.match("Insufficient balance", result)
assert.are.equal(0, balances.getBalance("test-wallet-address-2"))
assert.are.equal(100, balances.getBalance("test-wallet-address-1"))
assert.are.equal(0, balances.getBalance("test-this-is-valid-arweave-wallet-address-2"))
assert.are.equal(100, balances.getBalance("test-this-is-valid-arweave-wallet-address-1"))
end)
end)
Loading

0 comments on commit 58b690e

Please sign in to comment.