import { describe, expect, it } from 'vitest' import { shade } from './coin' /** * What a mark with no picture behind it is painted from. * * A shade that moves between screens or between reloads is noise wearing the * shape of a signal. The letters it goes under are `asset.ts`'s, beside the * resolver that derives them. */ describe('the shade', () => { const A = '0x4888e4a2ee0f03051c72d2bd3acf755ed3498b3e' const B = '0x94f49d0f4c62bbe4238f4aaa9200287bea9f2976' it('is the same every time for one address', () => { // The property that makes a mark recognisable at all. A shade recomputed // per render would be a different token on every screen. expect(shade(A)).toBe(shade(A)) }) it('does not depend on how the address was capitalised', () => { // Addresses arrive checksummed from a chain and lowercased from a wallet, // and one token with two marks is worse than no mark. expect(shade(A.toUpperCase().replace('0X', '0x'))).toBe(shade(A)) }) it('separates two different addresses', () => { expect(shade(A)).not.toBe(shade(B)) }) it('spreads real addresses across the band rather than bunching them', () => { // Summing character codes does not. Hex is a sixteen-character alphabet, so // every address lands in one narrow band — six real tokens all between 180 // and 344 of 360, two of them seventeen apart. FNV-1a mixes on every // character. const real = [ '0x0000000000000000000000000000000000000000', '0x4888e4a2ee0f03051c72d2bd3acf755ed3498b3e', '0x848cff46eb323f323b6bbe1df274e40793d7f2c2', '0x1e48d32a4f5e9f08db9ae4959163300faf8a6c8e', '0x5e5290f350352768bd2bfc59c2da15dd04a7cb88', '0x8031e9b0d02a792cfefaa2bdca6e1289d385426f', ] expect(new Set(real.map(shade)).size).toBeGreaterThanOrEqual(4) }) it('stays inside the band', () => { for (const a of [A, B, '', undefined]) { const s = shade(a) expect(s).toBeGreaterThanOrEqual(0) expect(s).toBeLessThan(12) } }) })