Investors on a revenue share take their cut of IPv4 lease income (#150)

Merged onto Island Wi-Fi: the revenue share base keeps the islands (V.wisp) and adds IPv4 leases (V.ip4); the CHANGELOG bullet goes above the Island Wi-Fi and Starblink ones.
This commit is contained in:
jvanvik 2026-11-12 01:04:52 +01:00
parent 6f0c080875
commit efe4405ea4
5 changed files with 46 additions and 6 deletions

View file

@ -171,6 +171,42 @@ test('buying, leasing in, leasing out and selling move the right money', (t) =>
assert.deepEqual(errors, []);
});
test('investors on a revenue share take their cut of IPv4 lease income, not of a sale', (t) => {
const { ev, dom, errors } = game(t);
homes(ev, 20);
ev("S.loanOffers.push({id:'v1',bank:'vult',amount:500000,exp:S.day+20,covs:['blitz'],share:0.1});ACT.takeLoan({id:'v1'})");
const base = () => ev('R.rev.eyeballs+R.rev.business+R.rev.ix+(R.rev.orbit||0)');
const rs0 = ev('R.cost.revshare');
assert.ok(rs0 > 0 && Math.abs(rs0 - 0.1 * base()) < 1e-6, 'the vultures take 10% of what homes pay');
ev('ACT.ip4Buy({len:20})');
const id = ev("S.ip4.b.find(b=>b.k==='buy').id");
ev(`ACT.ip4Out({id:${lit(id)}})`);
const lout = ev('R.rev.ip4');
assert.equal(lout, ev('ip4OutMo(20)'));
assert.ok(Math.abs(ev('R.cost.revshare') - 0.1 * (base() + lout)) < 1e-6, 'and 10% of the lease too');
assert.ok(Math.abs(ev('R.cost.revshare') - 0.1 * (ev('R.revMo') - ev('R.rev.grant||0') - ev('R.rev.gov||0'))) < 1, 'of everything but government money');
// A bank's big loan with a revenue share takes its share of the lease while it runs, and stops once repaid.
ev("S.loans.push({id:'b1',bank:'db',start:S.day,amount:2e6,got:2e6,bal:2e6,apr:0.1,apr0:0.1,pay:1,left:12,term:12,share:0.05,covs:[],base:{sub:0}});compute()");
assert.ok(Math.abs(ev('R.cost.revshare') - 0.15 * (base() + lout)) < 1e-6);
ev("S.loans.find(l=>l.id==='b1').bal=0;compute()");
assert.ok(Math.abs(ev('R.cost.revshare') - 0.1 * (base() + lout)) < 1e-6);
// Taking the block back ends the cut; selling it is a one-off that is all yours, like a fiber pair's up-front price.
ev(`ACT.ip4Back({id:${lit(id)}})`);
assert.equal(ev('R.rev.ip4'), undefined);
assert.ok(Math.abs(ev('R.cost.revshare') - rs0) < 1e-6);
ev('S.day+=730;compute()');
const rs1 = ev('R.cost.revshare'), cash = ev('S.cash');
ev(`ACT.ip4Sell({id:${lit(id)}});ACT.ip4Sell({id:${lit(id)}})`);
assert.equal(ev(`S.ip4.b.some(b=>b.id===${lit(id)})`), false);
assert.equal(ev('S.cash'), cash + ev('ip4Value(20)'));
assert.ok(Math.abs(ev('R.cost.revshare') - rs1) < 1e-6);
// The dashboard's Investor revenue share row shows the new amount.
ev("ACT.ip4Buy({len:20});ACT.ip4Out({id:S.ip4.b.filter(b=>b.k==='buy').pop().id});UI.dtab='overview';renderDash()");
assert.ok(ev('R.cost.revshare') > rs1, 'a new lease is shared again');
assert.ok(dom.window.document.getElementById('dash').textContent.includes(ev('fmt$(R.cost.revshare)')));
assert.deepEqual(errors, []);
});
test('a list of blocks stops where a save keeps them: buying and leasing past it is refused, and a full save loads whole', (t) => {
const { ev, dom, errors } = load({ agent: true });
t.after(() => dom.window.close());