Owner directive (2026-11-11): submit a single project to the NEAR Hackathon instead of two separate entries from the same person. Vendors Ration's NEAR audit-anchor work (github.com/caelum0x/ration, commit cff0ed3 + follow-ups) into ration-anchor/ as a first-class component: - contracts-near/audit_anchor (NEAR Rust contract, 5/5 cargo tests green, target/ deleted) - signer/ — a new, self-contained Go module (no dependency on Ration's other services or go.work) with the hand-rolled NEAR transaction signer + JSON-RPC client (cross-checked byte-for-byte against near-api-js) and the hash-chained audit ledger it anchors; 15/15 Go tests green (go test ./... -race) - docs/ and media/ — Ration's original pitch deck, demo recordings, and submission checklist Re-verified live via raw NEAR Testnet JSON-RPC this pass: ration-anchor-286ca315f1.testnet still deployed and queryable, the deliberate replay-rejection transaction still fails with nearcore's own "sequence must strictly advance" panic — no redeploy needed. Provenance notes added throughout (package doc comments, lib.rs header, README) crediting the origin repo. README.md and HACKATHON.md rewritten to tell one story: Cred402's SpendGuard enforces the protocol-level spending limit, the vendored Audit Anchor proves the tamper-evident spend history, both independently verifiable on NEAR Testnet. No mainnet claims anywhere (see prior overclaim fix 524f2dd). cred402's own build (npm run typecheck) and existing tests are untouched. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
81 lines
1.7 KiB
Go
81 lines
1.7 KiB
Go
package nearanchor
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
)
|
|
|
|
func TestBase58RoundTrip(t *testing.T) {
|
|
cases := [][]byte{
|
|
{},
|
|
{0},
|
|
{0, 0, 1},
|
|
{1, 2, 3, 4, 5},
|
|
bytes.Repeat([]byte{0xff}, 32),
|
|
}
|
|
for _, c := range cases {
|
|
encoded := base58Encode(c)
|
|
decoded, err := base58Decode(encoded)
|
|
if err != nil {
|
|
t.Fatalf("decode(%q): %v", encoded, err)
|
|
}
|
|
if !bytes.Equal(decoded, c) {
|
|
t.Fatalf("round trip mismatch: got %x, want %x (via %q)", decoded, c, encoded)
|
|
}
|
|
}
|
|
}
|
|
|
|
// TestBase58KnownVectors checks against values independently produced
|
|
// by near-api-js's own baseEncode/baseDecode (see keys_test.go's doc
|
|
// comment for how these were generated) rather than only trusting this
|
|
// file's own round trip.
|
|
func TestBase58KnownVectors(t *testing.T) {
|
|
cases := []struct {
|
|
hex string
|
|
b58 string
|
|
}{
|
|
{"00", "1"},
|
|
{"0000", "11"},
|
|
{"61", "2g"},
|
|
{"626262", "a3gV"},
|
|
{"68656c6c6f20776f726c64", "StV1DL6CwTryKyV"},
|
|
}
|
|
for _, c := range cases {
|
|
raw := mustHexDecode(t, c.hex)
|
|
if got := base58Encode(raw); got != c.b58 {
|
|
t.Errorf("base58Encode(%s) = %q, want %q", c.hex, got, c.b58)
|
|
}
|
|
decoded, err := base58Decode(c.b58)
|
|
if err != nil {
|
|
t.Fatalf("base58Decode(%q): %v", c.b58, err)
|
|
}
|
|
if !bytes.Equal(decoded, raw) {
|
|
t.Errorf("base58Decode(%q) = %x, want %x", c.b58, decoded, raw)
|
|
}
|
|
}
|
|
}
|
|
|
|
func mustHexDecode(t *testing.T, s string) []byte {
|
|
t.Helper()
|
|
b := make([]byte, len(s)/2)
|
|
for i := 0; i < len(b); i++ {
|
|
hi := hexNibble(t, s[i*2])
|
|
lo := hexNibble(t, s[i*2+1])
|
|
b[i] = hi<<4 | lo
|
|
}
|
|
return b
|
|
}
|
|
|
|
func hexNibble(t *testing.T, c byte) byte {
|
|
t.Helper()
|
|
switch {
|
|
case c >= '0' && c <= '9':
|
|
return c - '0'
|
|
case c >= 'a' && c <= 'f':
|
|
return c - 'a' + 10
|
|
default:
|
|
t.Fatalf("invalid hex char %q", c)
|
|
return 0
|
|
}
|
|
}
|