utils

package
v0.0.0-...-c37b867 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2024 License: GPL-2.0, GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HOURS_INT = 3600  // 1 hour in seconds
	DAYS_INT  = 86400 // 1 day in seconds
)

Variables

View Source
var (
	MockPost = tp.Post{
		Id:          1,
		Title:       "test",
		Author:      "tester",
		Contents:    "test contents",
		Tag:         0,
		Descriptors: "test;experimental;mocking",
		Time:        generateMockTime(),
	}
	MockReaction = tp.Reaction{
		Id:         1,
		PostId:     1,
		Descriptor: "experimental",
		Gravitas:   6,
	}
	MockReaction2 = tp.Reaction{
		Id:         2,
		PostId:     1,
		Descriptor: "mocking",
		Gravitas:   4,
	}
	MockHashes = [5]string{
		"UNUSEDc1884c7659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a09a",
		"PREVIOUS8184c7d659a2feaa0c55ad015a3bf4f1b2b0b82215d6c15b0f00a08a",
		"PENULTIMATE4c7d659a2feaa0c55ad015a3bf4f1b2b0b82215d6c15b0f00a0aa",
		"THIRDccc84c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a0ba",
		"GENESISccc87d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a0ba"}
	InvalidMockHashes = [3]string{
		"INVALIDc884c7659a2feaa0c55ad015a3bf4f1b2b0b822cd1a5d6c15b0f00a09",
		"ffa88d265a882b0716c60227e9ddb5c6a09542ec9b40b875463908a760ed0d6f",
		""}
	TestPosts = [7]tp.Post{
		{
			Title:       "test genesis post",
			Author:      "God",
			Contents:    `In the beginning God created the heavens and earth`,
			Tag:         0,
			Descriptors: "please overwrite me",
		},
		{
			Title:       "test first post",
			Author:      "welcomebot",
			Contents:    `Robots are cool`,
			Tag:         7,
			Descriptors: "please overwrite me",
		},
		{
			Title:    "test second post",
			Author:   "g yang",
			Contents: `do not worry child`,
			Tag:      4,
		},
		{
			Title:    "test 3 post",
			Author:   "welcomebot",
			Contents: `#ethereum`,
			Tag:      1,
		},
		{
			Title:    "test 4 post",
			Author:   "g yang",
			Contents: `boris out`,
			Tag:      6,
		},
		{
			Title:    "test 5 post",
			Author:   "dommedman",
			Contents: `orange pill`,
			Tag:      2,
		},
		{
			Title:    "test 6 post",
			Author:   "shapiro",
			Contents: "squeak, squeak",
			Tag:      5,
		},
	}
	TestInvalidPosts = [3]tp.Post{
		{
			Title:       "test genesis post",
			Author:      "God",
			Contents:    `this post has a duplicate title`,
			Tag:         0,
			Descriptors: "please overwrite me",
		},
		{
			Title:       "test other post 5",
			Author:      "author length than 10 chars",
			Contents:    `In the beginning God created the heavens and earth`,
			Tag:         0,
			Descriptors: "please overwrite me",
		},
		{
			Title:       "test other post 6",
			Author:      "anon",
			Contents:    "this post has no tag",
			Descriptors: "please overwrite me",
		},
	}
)

Data to populate this mock controller

Functions

func AwardDescriptors

func AwardDescriptors(reactions []tp.Reaction) []tp.Reaction

Returns and adds colour to the top 3 descriptors

func CheckDescriptor

func CheckDescriptor(descriptor, descriptors string) bool

Checks if the descriptor is in the descriptors string

func GenerateRawPasscode

func GenerateRawPasscode() string
Generates a new plain-text to lead the chain, that is moderately secure

in plaintext

func GetTagColour

func GetTagColour(tag int) string

Gets the tailwind CSS colour of a tag

func GetTimestring

func GetTimestring(moment time.Time) string

Gets a UI suitable time for the post

func Pkcs5Padding

func Pkcs5Padding(ciphertext []byte, blockSize int, after int) []byte

Boilerplate padding function

func Pkcs5Trimming

func Pkcs5Trimming(encrypt []byte) []byte

Boilerplate trimming function

func TimeSincePost

func TimeSincePost(isDays bool, lastPostTime time.Time) int

Gets the days since last post as int

func ValidateHashTiming

func ValidateHashTiming(lastPostTime time.Time, hashIndex int) bool
Validates if the provided hash index has the authority to make a post at

this time

func ValidateInputLength

func ValidateInputLength(p tp.Post) bool

Validates length of post input fields

Types

type MockController

type MockController struct{}

Mock database controller, used by all unit tests

func (*MockController) Clear

func (mc *MockController) Clear() bool

Mock method implementation

func (*MockController) Init

func (mc *MockController) Init() error

Mock method implementation

func (*MockController) InsertHash

func (mc *MockController) InsertHash(hash string) error

Mock method implementation

func (*MockController) InsertPost

func (mc *MockController) InsertPost(post tp.Post) error

Mock method implementation

func (*MockController) InsertReaction

func (mc *MockController) InsertReaction(reaction tp.Reaction) error

Mock method implementation

func (*MockController) SelectAnonReactionCount

func (mc *MockController) SelectAnonReactionCount(postId int) (int, error)

Mock method implementation

func (*MockController) SelectCandidateHashes

func (mc *MockController) SelectCandidateHashes() ([5]string, error)

Mock method implementation

func (*MockController) SelectDescriptors

func (mc *MockController) SelectDescriptors(postId int) (string, error)

Mock method implementation

func (*MockController) SelectLatestTimestamp

func (mc *MockController) SelectLatestTimestamp() (time.Time, error)

Mock method implementation

func (*MockController) SelectPostReactionHashes

func (mc *MockController) SelectPostReactionHashes(
	postId int) ([5]string, error)

Mock method implementation

func (*MockController) SelectPostReactions

func (mc *MockController) SelectPostReactions(
	postId int) ([]tp.Reaction, error)

Mock method implementation

func (*MockController) SelectPosts

func (mc *MockController) SelectPosts() ([]tp.Post, error)

Mock method implementation

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL