package native

import (
	"testing"
	"unicode"

	"git.marketally.com/tutus-one/tutus-chain/pkg/config"
	"github.com/stretchr/testify/require"
)

// "C" and "O" can easily be typed by accident.
func TestNamesASCII(t *testing.T) {
	cs := NewDefaultContracts(config.ProtocolConfiguration{})
	latestHF := config.HFLatestKnown
	for _, c := range cs {
		require.True(t, isASCII(c.Metadata().Name))
		hfMD := c.Metadata().HFSpecificContractMD(&latestHF)
		for _, m := range hfMD.Methods {
			require.True(t, isASCII(m.MD.Name))
		}
		for _, e := range hfMD.Manifest.ABI.Events {
			require.True(t, isASCII(e.Name))
		}
	}
}

func isASCII(s string) bool {
	ok := true
	for i := range s {
		ok = ok && s[i] <= unicode.MaxASCII
	}
	return ok
}
